未验证 提交 06cb9443 编写于 作者: A Alex Pelagenko 提交者: GitHub

fix(cairo): 6.1 migration issues (#1494)

上级 9b3651f2
......@@ -42,6 +42,8 @@ final class Mig607 {
path.trimTo(plen).concat(META_FILE_NAME).$();
long metaFileSize;
long txFileSize;
try (MemoryMARW metaMem = migrationContext.getRwMemory()) {
metaMem.of(ff, path, ff.getPageSize(), ff.length(path), MemoryTag.NATIVE_DEFAULT);
final int columnCount = metaMem.getInt(0);
......@@ -143,7 +145,30 @@ final class Mig607 {
denseSymbolCount++;
}
}
txFileSize = txMem.getAppendOffset();
}
metaFileSize = metaMem.getAppendOffset();
}
// This migration when written originally used implementation of MemoryMARW which truncated files to size on close
// MemoryMARW now truncate to page size. To test old migrations here we simulate the migration as it is originally released
// So trim TX and META files to their sizes
path.trimTo(plen).concat(META_FILE_NAME).$();
trimFile(ff, path, metaFileSize);
path.trimTo(plen).concat(TXN_FILE_NAME).$();
trimFile(ff, path, txFileSize);
}
private static void trimFile(FilesFacade ff, Path path, long size) {
long fd = TableUtils.openFileRWOrFail(ff, path);
if (!ff.truncate(fd, size)) {
// This should never happens on migration but better to be on safe side anyway
throw CairoException.instance(ff.errno()).put("Cannot trim to size [file=").put(path).put(']');
}
if (!ff.close(fd)) {
// This should never happens on migration but better to be on safe side anyway
throw CairoException.instance(ff.errno()).put("Cannot close [file=").put(path).put(']');
}
}
......
......@@ -85,7 +85,7 @@ final class Mig608 {
o = offset + thatMetaColumnDataSize * (columnCount - 1);
long o2 = offset + thisMetaColumnDataSize * (columnCount - 1);
final Rnd rnd = SharedRandom.getRandom(migrationContext.getConfiguration());
while (o > offset) {
while (o >= offset) {
rwMem.putInt(o2, rwMem.getInt(o)); // type
rwMem.putLong(o2 + 4, rwMem.getInt(o + 4)); // flags
rwMem.putInt(o2 + 12, rwMem.getInt(o + 12)); // index block capacity
......@@ -93,6 +93,7 @@ final class Mig608 {
o -= thatMetaColumnDataSize;
o2 -= thisMetaColumnDataSize;
}
rwMem.jumpTo(newNameOffset + nameSegmentLen);
}
// update _txn file
......@@ -119,6 +120,7 @@ final class Mig608 {
long thatSize = thatTxOffsetMapWriterCount + 4 + symbolCount * 8L + 4L + partitionTableSize;
long thisSize = thisTxOffsetMapWriterCount + 4 + symbolCount * 8L + 4L + partitionTableSize;
txMem.extend(thisSize);
txMem.jumpTo(thisSize);
Vect.memmove(txMem.addressOf(thisTxOffsetMapWriterCount), txMem.addressOf(thatTxOffsetMapWriterCount), thatSize - thatTxOffsetMapWriterCount);
// zero out reserved area
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册