fixed last data chunk size calculation
This commit is contained in:
parent
041849c2bd
commit
62d8ba9822
|
@ -217,7 +217,7 @@ export default class Conversion {
|
||||||
this._includeTables = this._config.include_tables === undefined ? [] : this._config.include_tables;
|
this._includeTables = this._config.include_tables === undefined ? [] : this._config.include_tables;
|
||||||
this._timeBegin = new Date();
|
this._timeBegin = new Date();
|
||||||
this._encoding = this._config.encoding === undefined ? 'utf8' : this._config.encoding;
|
this._encoding = this._config.encoding === undefined ? 'utf8' : this._config.encoding;
|
||||||
this._dataChunkSize = this._config.data_chunk_size === undefined ? 1 : +this._config.data_chunk_size;
|
this._dataChunkSize = this._config.data_chunk_size === undefined ? 1 : Math.ceil(+this._config.data_chunk_size);
|
||||||
this._dataChunkSize = this._dataChunkSize <= 0 ? 1 : this._dataChunkSize;
|
this._dataChunkSize = this._dataChunkSize <= 0 ? 1 : this._dataChunkSize;
|
||||||
this._0777 = '0777';
|
this._0777 = '0777';
|
||||||
this._mysqlVersion = '5.6.21'; // Simply a default value.
|
this._mysqlVersion = '5.6.21'; // Simply a default value.
|
||||||
|
|
|
@ -43,7 +43,7 @@ export default async (conversion: Conversion, tableName: string, haveDataChunksP
|
||||||
const dbAccess: DBAccess = new DBAccess(conversion);
|
const dbAccess: DBAccess = new DBAccess(conversion);
|
||||||
const sizeQueryResult: DBAccessQueryResult = await dbAccess.query(logTitle, sql, DBVendors.MYSQL, true, true);
|
const sizeQueryResult: DBAccessQueryResult = await dbAccess.query(logTitle, sql, DBVendors.MYSQL, true, true);
|
||||||
|
|
||||||
const tableSizeInMb: number = +sizeQueryResult.data[0].size_in_mb;
|
const tableSizeInMb: number = Math.ceil(+sizeQueryResult.data[0].size_in_mb);
|
||||||
const strSelectFieldList: string = arrangeColumnsData(conversion._dicTables[tableName].arrTableColumns, conversion._mysqlVersion);
|
const strSelectFieldList: string = arrangeColumnsData(conversion._dicTables[tableName].arrTableColumns, conversion._mysqlVersion);
|
||||||
sql = `SELECT COUNT(1) AS rows_count FROM \`${ originalTableName }\`;`;
|
sql = `SELECT COUNT(1) AS rows_count FROM \`${ originalTableName }\`;`;
|
||||||
const countResult: DBAccessQueryResult = await dbAccess.query(
|
const countResult: DBAccessQueryResult = await dbAccess.query(
|
||||||
|
@ -56,8 +56,7 @@ export default async (conversion: Conversion, tableName: string, haveDataChunksP
|
||||||
);
|
);
|
||||||
|
|
||||||
const rowsCnt: number = countResult.data[0].rows_count;
|
const rowsCnt: number = countResult.data[0].rows_count;
|
||||||
let chunksCnt: number = tableSizeInMb / conversion._dataChunkSize;
|
const chunksCnt: number = Math.ceil(tableSizeInMb / conversion._dataChunkSize);
|
||||||
chunksCnt = chunksCnt < 1 ? 1 : chunksCnt;
|
|
||||||
const rowsInChunk: number = Math.ceil(rowsCnt / chunksCnt);
|
const rowsInChunk: number = Math.ceil(rowsCnt / chunksCnt);
|
||||||
const arrDataPoolPromises: Promise<void>[] = [];
|
const arrDataPoolPromises: Promise<void>[] = [];
|
||||||
const msg: string = `\t--[prepareDataChunks] Total rows to insert into "${ conversion._schema }"."${ tableName }": ${ rowsCnt }`;
|
const msg: string = `\t--[prepareDataChunks] Total rows to insert into "${ conversion._schema }"."${ tableName }": ${ rowsCnt }`;
|
||||||
|
@ -78,8 +77,8 @@ export default async (conversion: Conversion, tableName: string, haveDataChunksP
|
||||||
if (chunksCnt === 1) {
|
if (chunksCnt === 1) {
|
||||||
currentChunkSizeInMb = tableSizeInMb;
|
currentChunkSizeInMb = tableSizeInMb;
|
||||||
} else if (offset + rowsInChunk >= rowsCnt) {
|
} else if (offset + rowsInChunk >= rowsCnt) {
|
||||||
currentChunkSizeInMb = tableSizeInMb % chunksCnt;
|
// !!!Note, it can happen only on the last iteration, when defining a size of the last chunk.
|
||||||
currentChunkSizeInMb = currentChunkSizeInMb || conversion._dataChunkSize;
|
currentChunkSizeInMb = tableSizeInMb - conversion._dataChunkSize * (chunksCnt - 1);
|
||||||
} else {
|
} else {
|
||||||
currentChunkSizeInMb = conversion._dataChunkSize;
|
currentChunkSizeInMb = conversion._dataChunkSize;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue