use of org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord in project ignite by apache.
the class PagesList method doMerge.
/**
* @param pageId Page ID.
* @param page Page absolute pointer.
* @param pageAddr Page address.
* @param io IO.
* @param nextId Next page ID.
* @param nextPage Next page absolute pointer.
* @param nextAddr Next page address.
* @param bucket Bucket index.
* @param statHolder Statistics holder to track IO operations.
* @return Page to recycle.
* @throws IgniteCheckedException If failed.
*/
private long doMerge(long pageId, long page, long pageAddr, PagesListNodeIO io, long nextId, long nextPage, long nextAddr, int bucket, IoStatisticsHolder statHolder) throws IgniteCheckedException {
long prevId = io.getPreviousId(pageAddr);
if (nextId == 0L)
return mergeNoNext(pageId, page, pageAddr, prevId, bucket, statHolder);
else {
// No one must be able to merge it while we keep a reference.
assert getPageId(nextAddr) == nextId;
if (prevId == 0L) {
// These references must be updated at the same time in write locks.
assert PagesListNodeIO.VERSIONS.forPage(nextAddr).getPreviousId(nextAddr) == pageId;
PagesListNodeIO nextIO = PagesListNodeIO.VERSIONS.forPage(nextAddr);
nextIO.setPreviousId(nextAddr, 0);
if (needWalDeltaRecord(nextId, nextPage, null))
wal.log(new PagesListSetPreviousRecord(grpId, nextId, 0L));
} else
// Do a fair merge: link previous and next to each other.
fairMerge(prevId, pageId, nextId, nextPage, nextAddr, statHolder);
return recyclePage(pageId, page, pageAddr, null);
}
}
use of org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord in project ignite by apache.
the class RecordDataV1Serializer method readPlainRecord.
/**
* Reads {@code WalRecord} of {@code type} from input.
* Input should be plain(not encrypted).
*
* @param type Record type.
* @param in Input
* @param encrypted Record was encrypted.
* @param recordSize Record size.
* @return Deserialized record.
* @throws IOException If failed.
* @throws IgniteCheckedException If failed.
*/
WALRecord readPlainRecord(RecordType type, ByteBufferBackedDataInput in, boolean encrypted, int recordSize) throws IOException, IgniteCheckedException {
WALRecord res;
switch(type) {
case PAGE_RECORD:
byte[] arr = new byte[pageSize];
int cacheId = in.readInt();
long pageId = in.readLong();
in.readFully(arr);
res = new PageSnapshot(new FullPageId(pageId, cacheId), arr, encrypted ? realPageSize : pageSize);
break;
case CHECKPOINT_RECORD:
long msb = in.readLong();
long lsb = in.readLong();
boolean hasPtr = in.readByte() != 0;
long idx = hasPtr ? in.readLong() : 0;
int off = hasPtr ? in.readInt() : 0;
int len = hasPtr ? in.readInt() : 0;
Map<Integer, CacheState> states = readPartitionStates(in);
boolean end = in.readByte() != 0;
WALPointer walPtr = hasPtr ? new WALPointer(idx, off, len) : null;
CheckpointRecord cpRec = new CheckpointRecord(new UUID(msb, lsb), walPtr, end);
cpRec.cacheGroupStates(states);
res = cpRec;
break;
case META_PAGE_INIT:
cacheId = in.readInt();
pageId = in.readLong();
int ioType = in.readUnsignedShort();
int ioVer = in.readUnsignedShort();
long treeRoot = in.readLong();
long reuseListRoot = in.readLong();
res = new MetaPageInitRecord(cacheId, pageId, ioType, ioVer, treeRoot, reuseListRoot, log);
break;
case INDEX_META_PAGE_DELTA_RECORD:
res = new MetaPageUpdateIndexDataRecord(in);
break;
case PARTITION_META_PAGE_UPDATE_COUNTERS:
res = new MetaPageUpdatePartitionDataRecord(in);
break;
case PARTITION_META_PAGE_UPDATE_COUNTERS_V2:
res = new MetaPageUpdatePartitionDataRecordV2(in);
break;
case PARTITION_META_PAGE_DELTA_RECORD_V3:
res = new MetaPageUpdatePartitionDataRecordV3(in);
break;
case MEMORY_RECOVERY:
long ts = in.readLong();
res = new MemoryRecoveryRecord(ts);
break;
case PARTITION_DESTROY:
cacheId = in.readInt();
int partId = in.readInt();
res = new PartitionDestroyRecord(cacheId, partId);
break;
case DATA_RECORD:
case DATA_RECORD_V2:
int entryCnt = in.readInt();
if (entryCnt == 1)
res = new DataRecord(readPlainDataEntry(in, type), 0L);
else {
List<DataEntry> entries = new ArrayList<>(entryCnt);
for (int i = 0; i < entryCnt; i++) entries.add(readPlainDataEntry(in, type));
res = new DataRecord(entries, 0L);
}
break;
case ENCRYPTED_DATA_RECORD:
case ENCRYPTED_DATA_RECORD_V2:
case ENCRYPTED_DATA_RECORD_V3:
entryCnt = in.readInt();
if (entryCnt == 1)
res = new DataRecord(readEncryptedDataEntry(in, type), 0L);
else {
List<DataEntry> entries = new ArrayList<>(entryCnt);
for (int i = 0; i < entryCnt; i++) entries.add(readEncryptedDataEntry(in, type));
res = new DataRecord(entries, 0L);
}
break;
case METASTORE_DATA_RECORD:
int strLen = in.readInt();
byte[] strBytes = new byte[strLen];
in.readFully(strBytes);
String key = new String(strBytes);
int valLen = in.readInt();
assert valLen >= 0;
byte[] val;
if (valLen > 0) {
val = new byte[valLen];
in.readFully(val);
} else
val = null;
return new MetastoreDataRecord(key, val);
case HEADER_RECORD:
long magic = in.readLong();
if (magic != HeaderRecord.REGULAR_MAGIC && magic != HeaderRecord.COMPACTED_MAGIC)
throw new EOFException("Magic is corrupted [actual=" + U.hexLong(magic) + ']');
int ver = in.readInt();
res = new HeaderRecord(ver);
break;
case DATA_PAGE_INSERT_RECORD:
{
cacheId = in.readInt();
pageId = in.readLong();
int size = in.readUnsignedShort();
in.ensure(size);
byte[] payload = new byte[size];
in.readFully(payload);
res = new DataPageInsertRecord(cacheId, pageId, payload);
break;
}
case DATA_PAGE_UPDATE_RECORD:
{
cacheId = in.readInt();
pageId = in.readLong();
int itemId = in.readInt();
int size = in.readUnsignedShort();
in.ensure(size);
byte[] payload = new byte[size];
in.readFully(payload);
res = new DataPageUpdateRecord(cacheId, pageId, itemId, payload);
break;
}
case DATA_PAGE_INSERT_FRAGMENT_RECORD:
{
cacheId = in.readInt();
pageId = in.readLong();
final long lastLink = in.readLong();
final int payloadSize = in.readInt();
final byte[] payload = new byte[payloadSize];
in.readFully(payload);
res = new DataPageInsertFragmentRecord(cacheId, pageId, payload, lastLink);
break;
}
case DATA_PAGE_REMOVE_RECORD:
cacheId = in.readInt();
pageId = in.readLong();
int itemId = in.readUnsignedByte();
res = new DataPageRemoveRecord(cacheId, pageId, itemId);
break;
case DATA_PAGE_SET_FREE_LIST_PAGE:
cacheId = in.readInt();
pageId = in.readLong();
long freeListPage = in.readLong();
res = new DataPageSetFreeListPageRecord(cacheId, pageId, freeListPage);
break;
case MVCC_DATA_PAGE_MARK_UPDATED_RECORD:
cacheId = in.readInt();
pageId = in.readLong();
itemId = in.readInt();
long newMvccCrd = in.readLong();
long newMvccCntr = in.readLong();
int newMvccOpCntr = in.readInt();
res = new DataPageMvccMarkUpdatedRecord(cacheId, pageId, itemId, newMvccCrd, newMvccCntr, newMvccOpCntr);
break;
case MVCC_DATA_PAGE_TX_STATE_HINT_UPDATED_RECORD:
cacheId = in.readInt();
pageId = in.readLong();
itemId = in.readInt();
byte txState = in.readByte();
res = new DataPageMvccUpdateTxStateHintRecord(cacheId, pageId, itemId, txState);
break;
case MVCC_DATA_PAGE_NEW_TX_STATE_HINT_UPDATED_RECORD:
cacheId = in.readInt();
pageId = in.readLong();
itemId = in.readInt();
byte newTxState = in.readByte();
res = new DataPageMvccUpdateNewTxStateHintRecord(cacheId, pageId, itemId, newTxState);
break;
case INIT_NEW_PAGE_RECORD:
cacheId = in.readInt();
pageId = in.readLong();
ioType = in.readUnsignedShort();
ioVer = in.readUnsignedShort();
long virtualPageId = in.readLong();
res = new InitNewPageRecord(cacheId, pageId, ioType, ioVer, virtualPageId, log);
break;
case BTREE_META_PAGE_INIT_ROOT:
cacheId = in.readInt();
pageId = in.readLong();
long rootId = in.readLong();
res = new MetaPageInitRootRecord(cacheId, pageId, rootId);
break;
case BTREE_META_PAGE_INIT_ROOT2:
cacheId = in.readInt();
pageId = in.readLong();
long rootId2 = in.readLong();
int inlineSize = in.readShort();
res = new MetaPageInitRootInlineRecord(cacheId, pageId, rootId2, inlineSize);
break;
case BTREE_META_PAGE_INIT_ROOT_V3:
cacheId = in.readInt();
pageId = in.readLong();
long rootId3 = in.readLong();
int inlineSize3 = in.readShort();
long flags = in.readLong();
byte[] revHash = new byte[IgniteProductVersion.REV_HASH_SIZE];
byte maj = in.readByte();
byte min = in.readByte();
byte maint = in.readByte();
long verTs = in.readLong();
in.readFully(revHash);
IgniteProductVersion createdVer = new IgniteProductVersion(maj, min, maint, verTs, revHash);
res = new MetaPageInitRootInlineFlagsCreatedVersionRecord(cacheId, pageId, rootId3, inlineSize3, flags, createdVer);
break;
case BTREE_META_PAGE_ADD_ROOT:
cacheId = in.readInt();
pageId = in.readLong();
rootId = in.readLong();
res = new MetaPageAddRootRecord(cacheId, pageId, rootId);
break;
case BTREE_META_PAGE_CUT_ROOT:
cacheId = in.readInt();
pageId = in.readLong();
res = new MetaPageCutRootRecord(cacheId, pageId);
break;
case BTREE_INIT_NEW_ROOT:
cacheId = in.readInt();
pageId = in.readLong();
rootId = in.readLong();
ioType = in.readUnsignedShort();
ioVer = in.readUnsignedShort();
long leftId = in.readLong();
long rightId = in.readLong();
BPlusIO<?> io = BPlusIO.getBPlusIO(ioType, ioVer);
byte[] rowBytes = new byte[io.getItemSize()];
in.readFully(rowBytes);
res = new NewRootInitRecord<>(cacheId, pageId, rootId, (BPlusInnerIO<?>) io, leftId, rowBytes, rightId);
break;
case BTREE_PAGE_RECYCLE:
cacheId = in.readInt();
pageId = in.readLong();
long newPageId = in.readLong();
res = new RecycleRecord(cacheId, pageId, newPageId);
break;
case BTREE_PAGE_INSERT:
cacheId = in.readInt();
pageId = in.readLong();
ioType = in.readUnsignedShort();
ioVer = in.readUnsignedShort();
int itemIdx = in.readUnsignedShort();
rightId = in.readLong();
io = BPlusIO.getBPlusIO(ioType, ioVer);
rowBytes = new byte[io.getItemSize()];
in.readFully(rowBytes);
res = new InsertRecord<>(cacheId, pageId, io, itemIdx, rowBytes, rightId);
break;
case BTREE_FIX_LEFTMOST_CHILD:
cacheId = in.readInt();
pageId = in.readLong();
rightId = in.readLong();
res = new FixLeftmostChildRecord(cacheId, pageId, rightId);
break;
case BTREE_FIX_COUNT:
cacheId = in.readInt();
pageId = in.readLong();
int cnt = in.readUnsignedShort();
res = new FixCountRecord(cacheId, pageId, cnt);
break;
case BTREE_PAGE_REPLACE:
cacheId = in.readInt();
pageId = in.readLong();
ioType = in.readUnsignedShort();
ioVer = in.readUnsignedShort();
itemIdx = in.readUnsignedShort();
io = BPlusIO.getBPlusIO(ioType, ioVer);
rowBytes = new byte[io.getItemSize()];
in.readFully(rowBytes);
res = new ReplaceRecord<>(cacheId, pageId, io, rowBytes, itemIdx);
break;
case BTREE_PAGE_REMOVE:
cacheId = in.readInt();
pageId = in.readLong();
itemIdx = in.readUnsignedShort();
cnt = in.readUnsignedShort();
res = new RemoveRecord(cacheId, pageId, itemIdx, cnt);
break;
case BTREE_PAGE_INNER_REPLACE:
cacheId = in.readInt();
pageId = in.readLong();
int dstIdx = in.readUnsignedShort();
long srcPageId = in.readLong();
int srcIdx = in.readUnsignedShort();
long rmvId = in.readLong();
res = new InnerReplaceRecord<>(cacheId, pageId, dstIdx, srcPageId, srcIdx, rmvId);
break;
case BTREE_FORWARD_PAGE_SPLIT:
cacheId = in.readInt();
pageId = in.readLong();
long fwdId = in.readLong();
ioType = in.readUnsignedShort();
ioVer = in.readUnsignedShort();
srcPageId = in.readLong();
int mid = in.readUnsignedShort();
cnt = in.readUnsignedShort();
res = new SplitForwardPageRecord(cacheId, pageId, fwdId, ioType, ioVer, srcPageId, mid, cnt);
break;
case BTREE_EXISTING_PAGE_SPLIT:
cacheId = in.readInt();
pageId = in.readLong();
mid = in.readUnsignedShort();
fwdId = in.readLong();
res = new SplitExistingPageRecord(cacheId, pageId, mid, fwdId);
break;
case BTREE_PAGE_MERGE:
cacheId = in.readInt();
pageId = in.readLong();
long prntId = in.readLong();
int prntIdx = in.readUnsignedShort();
rightId = in.readLong();
boolean emptyBranch = in.readBoolean();
res = new MergeRecord<>(cacheId, pageId, prntId, prntIdx, rightId, emptyBranch);
break;
case BTREE_FIX_REMOVE_ID:
cacheId = in.readInt();
pageId = in.readLong();
rmvId = in.readLong();
res = new FixRemoveId(cacheId, pageId, rmvId);
break;
case PAGES_LIST_SET_NEXT:
cacheId = in.readInt();
pageId = in.readLong();
long nextPageId = in.readLong();
res = new PagesListSetNextRecord(cacheId, pageId, nextPageId);
break;
case PAGES_LIST_SET_PREVIOUS:
cacheId = in.readInt();
pageId = in.readLong();
long prevPageId = in.readLong();
res = new PagesListSetPreviousRecord(cacheId, pageId, prevPageId);
break;
case PAGES_LIST_INIT_NEW_PAGE:
cacheId = in.readInt();
pageId = in.readLong();
ioType = in.readInt();
ioVer = in.readInt();
newPageId = in.readLong();
prevPageId = in.readLong();
long addDataPageId = in.readLong();
res = new PagesListInitNewPageRecord(cacheId, pageId, ioType, ioVer, newPageId, prevPageId, addDataPageId, log);
break;
case PAGES_LIST_ADD_PAGE:
cacheId = in.readInt();
pageId = in.readLong();
long dataPageId = in.readLong();
res = new PagesListAddPageRecord(cacheId, pageId, dataPageId);
break;
case PAGES_LIST_REMOVE_PAGE:
cacheId = in.readInt();
pageId = in.readLong();
long rmvdPageId = in.readLong();
res = new PagesListRemovePageRecord(cacheId, pageId, rmvdPageId);
break;
case TRACKING_PAGE_DELTA:
cacheId = in.readInt();
pageId = in.readLong();
long pageIdToMark = in.readLong();
long nextSnapshotId0 = in.readLong();
long lastSuccessfulSnapshotId0 = in.readLong();
res = new TrackingPageDeltaRecord(cacheId, pageId, pageIdToMark, nextSnapshotId0, lastSuccessfulSnapshotId0);
break;
case META_PAGE_UPDATE_NEXT_SNAPSHOT_ID:
cacheId = in.readInt();
pageId = in.readLong();
long nextSnapshotId = in.readLong();
res = new MetaPageUpdateNextSnapshotId(cacheId, pageId, nextSnapshotId);
break;
case META_PAGE_UPDATE_LAST_SUCCESSFUL_FULL_SNAPSHOT_ID:
cacheId = in.readInt();
pageId = in.readLong();
long lastSuccessfulFullSnapshotId = in.readLong();
res = new MetaPageUpdateLastSuccessfulFullSnapshotId(cacheId, pageId, lastSuccessfulFullSnapshotId);
break;
case META_PAGE_UPDATE_LAST_SUCCESSFUL_SNAPSHOT_ID:
cacheId = in.readInt();
pageId = in.readLong();
long lastSuccessfulSnapshotId = in.readLong();
long lastSuccessfulSnapshotTag = in.readLong();
res = new MetaPageUpdateLastSuccessfulSnapshotId(cacheId, pageId, lastSuccessfulSnapshotId, lastSuccessfulSnapshotTag);
break;
case META_PAGE_UPDATE_LAST_ALLOCATED_INDEX:
cacheId = in.readInt();
pageId = in.readLong();
int lastAllocatedIdx = in.readInt();
res = new MetaPageUpdateLastAllocatedIndex(cacheId, pageId, lastAllocatedIdx);
break;
case PART_META_UPDATE_STATE:
cacheId = in.readInt();
partId = in.readInt();
byte state = in.readByte();
long updateCntr = in.readLong();
GridDhtPartitionState partState = GridDhtPartitionState.fromOrdinal(state);
res = new PartitionMetaStateRecord(cacheId, partId, partState, updateCntr);
break;
case PAGE_LIST_META_RESET_COUNT_RECORD:
cacheId = in.readInt();
pageId = in.readLong();
res = new PageListMetaResetCountRecord(cacheId, pageId);
break;
case ROTATED_ID_PART_RECORD:
cacheId = in.readInt();
pageId = in.readLong();
byte rotatedIdPart = in.readByte();
res = new RotatedIdPartRecord(cacheId, pageId, rotatedIdPart);
break;
case SWITCH_SEGMENT_RECORD:
throw new EOFException("END OF SEGMENT");
case TX_RECORD:
res = txRecordSerializer.readTx(in);
break;
case MASTER_KEY_CHANGE_RECORD:
case MASTER_KEY_CHANGE_RECORD_V2:
int keyNameLen = in.readInt();
byte[] keyNameBytes = new byte[keyNameLen];
in.readFully(keyNameBytes);
String masterKeyName = new String(keyNameBytes);
int keysCnt = in.readInt();
List<T2<Integer, GroupKeyEncrypted>> grpKeys = new ArrayList<>(keysCnt);
boolean readKeyId = type == MASTER_KEY_CHANGE_RECORD_V2;
for (int i = 0; i < keysCnt; i++) {
int grpId = in.readInt();
int keyId = readKeyId ? in.readByte() & 0xff : 0;
int grpKeySize = in.readInt();
byte[] grpKey = new byte[grpKeySize];
in.readFully(grpKey);
grpKeys.add(new T2<>(grpId, new GroupKeyEncrypted(keyId, grpKey)));
}
res = new MasterKeyChangeRecordV2(masterKeyName, grpKeys);
break;
case REENCRYPTION_START_RECORD:
int grpsCnt = in.readInt();
Map<Integer, Byte> map = U.newHashMap(grpsCnt);
for (int i = 0; i < grpsCnt; i++) {
int grpId = in.readInt();
byte keyId = in.readByte();
map.put(grpId, keyId);
}
res = new ReencryptionStartRecord(map);
break;
case INDEX_ROOT_PAGE_RENAME_RECORD:
res = new IndexRenameRootPageRecord(in);
break;
case PARTITION_CLEARING_START_RECORD:
int partId0 = in.readInt();
int grpId = in.readInt();
long clearVer = in.readLong();
res = new PartitionClearingStartRecord(partId0, grpId, clearVer);
break;
default:
throw new UnsupportedOperationException("Type: " + type);
}
return res;
}
use of org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord in project ignite by apache.
the class RecordDataV1Serializer method writePlainRecord.
/**
* Write {@code rec} to {@code buf} without encryption.
*
* @param rec Record to serialize.
* @param buf Output buffer.
* @throws IgniteCheckedException If failed.
*/
void writePlainRecord(WALRecord rec, ByteBuffer buf) throws IgniteCheckedException {
switch(rec.type()) {
case PAGE_RECORD:
PageSnapshot snap = (PageSnapshot) rec;
buf.putInt(snap.fullPageId().groupId());
buf.putLong(snap.fullPageId().pageId());
buf.put(snap.pageDataBuffer());
break;
case MEMORY_RECOVERY:
MemoryRecoveryRecord memoryRecoveryRecord = (MemoryRecoveryRecord) rec;
buf.putLong(memoryRecoveryRecord.time());
break;
case PARTITION_DESTROY:
PartitionDestroyRecord partDestroy = (PartitionDestroyRecord) rec;
buf.putInt(partDestroy.groupId());
buf.putInt(partDestroy.partitionId());
break;
case META_PAGE_INIT:
MetaPageInitRecord updRootsRec = (MetaPageInitRecord) rec;
buf.putInt(updRootsRec.groupId());
buf.putLong(updRootsRec.pageId());
buf.putShort((short) updRootsRec.ioType());
buf.putShort((short) updRootsRec.ioVersion());
buf.putLong(updRootsRec.treeRoot());
buf.putLong(updRootsRec.reuseListRoot());
break;
case INDEX_META_PAGE_DELTA_RECORD:
((MetaPageUpdateIndexDataRecord) rec).toBytes(buf);
break;
case PARTITION_META_PAGE_UPDATE_COUNTERS:
case PARTITION_META_PAGE_UPDATE_COUNTERS_V2:
case PARTITION_META_PAGE_DELTA_RECORD_V3:
((MetaPageUpdatePartitionDataRecord) rec).toBytes(buf);
break;
case CHECKPOINT_RECORD:
CheckpointRecord cpRec = (CheckpointRecord) rec;
WALPointer walPtr = cpRec.checkpointMark();
UUID cpId = cpRec.checkpointId();
buf.putLong(cpId.getMostSignificantBits());
buf.putLong(cpId.getLeastSignificantBits());
buf.put(walPtr == null ? (byte) 0 : 1);
if (walPtr != null) {
buf.putLong(walPtr.index());
buf.putInt(walPtr.fileOffset());
buf.putInt(walPtr.length());
}
putCacheStates(buf, cpRec.cacheGroupStates());
buf.put(cpRec.end() ? (byte) 1 : 0);
break;
case DATA_RECORD_V2:
DataRecord dataRec = (DataRecord) rec;
int entryCnt = dataRec.entryCount();
buf.putInt(entryCnt);
boolean encrypted = isDataRecordEncrypted(dataRec);
for (int i = 0; i < entryCnt; i++) {
if (encrypted)
putEncryptedDataEntry(buf, dataRec.get(i));
else
putPlainDataEntry(buf, dataRec.get(i));
}
break;
case METASTORE_DATA_RECORD:
MetastoreDataRecord metastoreDataRecord = (MetastoreDataRecord) rec;
byte[] strBytes = metastoreDataRecord.key().getBytes();
buf.putInt(strBytes.length);
buf.put(strBytes);
if (metastoreDataRecord.value() != null) {
buf.putInt(metastoreDataRecord.value().length);
buf.put(metastoreDataRecord.value());
} else
buf.putInt(0);
break;
case HEADER_RECORD:
buf.putLong(HeaderRecord.REGULAR_MAGIC);
buf.putInt(((HeaderRecord) rec).version());
break;
case DATA_PAGE_INSERT_RECORD:
DataPageInsertRecord diRec = (DataPageInsertRecord) rec;
buf.putInt(diRec.groupId());
buf.putLong(diRec.pageId());
buf.putShort((short) diRec.payload().length);
buf.put(diRec.payload());
break;
case DATA_PAGE_UPDATE_RECORD:
DataPageUpdateRecord uRec = (DataPageUpdateRecord) rec;
buf.putInt(uRec.groupId());
buf.putLong(uRec.pageId());
buf.putInt(uRec.itemId());
buf.putShort((short) uRec.payload().length);
buf.put(uRec.payload());
break;
case DATA_PAGE_INSERT_FRAGMENT_RECORD:
final DataPageInsertFragmentRecord difRec = (DataPageInsertFragmentRecord) rec;
buf.putInt(difRec.groupId());
buf.putLong(difRec.pageId());
buf.putLong(difRec.lastLink());
buf.putInt(difRec.payloadSize());
buf.put(difRec.payload());
break;
case DATA_PAGE_REMOVE_RECORD:
DataPageRemoveRecord drRec = (DataPageRemoveRecord) rec;
buf.putInt(drRec.groupId());
buf.putLong(drRec.pageId());
buf.put((byte) drRec.itemId());
break;
case DATA_PAGE_SET_FREE_LIST_PAGE:
DataPageSetFreeListPageRecord freeListRec = (DataPageSetFreeListPageRecord) rec;
buf.putInt(freeListRec.groupId());
buf.putLong(freeListRec.pageId());
buf.putLong(freeListRec.freeListPage());
break;
case MVCC_DATA_PAGE_MARK_UPDATED_RECORD:
DataPageMvccMarkUpdatedRecord rmvRec = (DataPageMvccMarkUpdatedRecord) rec;
buf.putInt(rmvRec.groupId());
buf.putLong(rmvRec.pageId());
buf.putInt(rmvRec.itemId());
buf.putLong(rmvRec.newMvccCrd());
buf.putLong(rmvRec.newMvccCntr());
buf.putInt(rmvRec.newMvccOpCntr());
break;
case MVCC_DATA_PAGE_TX_STATE_HINT_UPDATED_RECORD:
DataPageMvccUpdateTxStateHintRecord txStRec = (DataPageMvccUpdateTxStateHintRecord) rec;
buf.putInt(txStRec.groupId());
buf.putLong(txStRec.pageId());
buf.putInt(txStRec.itemId());
buf.put(txStRec.txState());
break;
case MVCC_DATA_PAGE_NEW_TX_STATE_HINT_UPDATED_RECORD:
DataPageMvccUpdateNewTxStateHintRecord newTxStRec = (DataPageMvccUpdateNewTxStateHintRecord) rec;
buf.putInt(newTxStRec.groupId());
buf.putLong(newTxStRec.pageId());
buf.putInt(newTxStRec.itemId());
buf.put(newTxStRec.txState());
break;
case INIT_NEW_PAGE_RECORD:
InitNewPageRecord inpRec = (InitNewPageRecord) rec;
buf.putInt(inpRec.groupId());
buf.putLong(inpRec.pageId());
buf.putShort((short) inpRec.ioType());
buf.putShort((short) inpRec.ioVersion());
buf.putLong(inpRec.newPageId());
break;
case BTREE_META_PAGE_INIT_ROOT:
MetaPageInitRootRecord imRec = (MetaPageInitRootRecord) rec;
buf.putInt(imRec.groupId());
buf.putLong(imRec.pageId());
buf.putLong(imRec.rootId());
break;
case BTREE_META_PAGE_INIT_ROOT2:
MetaPageInitRootInlineRecord imRec2 = (MetaPageInitRootInlineRecord) rec;
buf.putInt(imRec2.groupId());
buf.putLong(imRec2.pageId());
buf.putLong(imRec2.rootId());
buf.putShort((short) imRec2.inlineSize());
break;
case BTREE_META_PAGE_INIT_ROOT_V3:
MetaPageInitRootInlineFlagsCreatedVersionRecord imRec3 = (MetaPageInitRootInlineFlagsCreatedVersionRecord) rec;
buf.putInt(imRec3.groupId());
buf.putLong(imRec3.pageId());
buf.putLong(imRec3.rootId());
buf.putShort((short) imRec3.inlineSize());
buf.putLong(imRec3.flags());
// Write created version.
IgniteProductVersion createdVer = imRec3.createdVersion();
buf.put(createdVer.major());
buf.put(createdVer.minor());
buf.put(createdVer.maintenance());
buf.putLong(createdVer.revisionTimestamp());
buf.put(createdVer.revisionHash());
break;
case BTREE_META_PAGE_ADD_ROOT:
MetaPageAddRootRecord arRec = (MetaPageAddRootRecord) rec;
buf.putInt(arRec.groupId());
buf.putLong(arRec.pageId());
buf.putLong(arRec.rootId());
break;
case BTREE_META_PAGE_CUT_ROOT:
MetaPageCutRootRecord crRec = (MetaPageCutRootRecord) rec;
buf.putInt(crRec.groupId());
buf.putLong(crRec.pageId());
break;
case BTREE_INIT_NEW_ROOT:
NewRootInitRecord<?> riRec = (NewRootInitRecord<?>) rec;
buf.putInt(riRec.groupId());
buf.putLong(riRec.pageId());
buf.putLong(riRec.rootId());
buf.putShort((short) riRec.io().getType());
buf.putShort((short) riRec.io().getVersion());
buf.putLong(riRec.leftId());
buf.putLong(riRec.rightId());
putRow(buf, riRec.rowBytes());
break;
case BTREE_PAGE_RECYCLE:
RecycleRecord recRec = (RecycleRecord) rec;
buf.putInt(recRec.groupId());
buf.putLong(recRec.pageId());
buf.putLong(recRec.newPageId());
break;
case BTREE_PAGE_INSERT:
InsertRecord<?> inRec = (InsertRecord<?>) rec;
buf.putInt(inRec.groupId());
buf.putLong(inRec.pageId());
buf.putShort((short) inRec.io().getType());
buf.putShort((short) inRec.io().getVersion());
buf.putShort((short) inRec.index());
buf.putLong(inRec.rightId());
putRow(buf, inRec.rowBytes());
break;
case BTREE_FIX_LEFTMOST_CHILD:
FixLeftmostChildRecord flRec = (FixLeftmostChildRecord) rec;
buf.putInt(flRec.groupId());
buf.putLong(flRec.pageId());
buf.putLong(flRec.rightId());
break;
case BTREE_FIX_COUNT:
FixCountRecord fcRec = (FixCountRecord) rec;
buf.putInt(fcRec.groupId());
buf.putLong(fcRec.pageId());
buf.putShort((short) fcRec.count());
break;
case BTREE_PAGE_REPLACE:
ReplaceRecord<?> rRec = (ReplaceRecord<?>) rec;
buf.putInt(rRec.groupId());
buf.putLong(rRec.pageId());
buf.putShort((short) rRec.io().getType());
buf.putShort((short) rRec.io().getVersion());
buf.putShort((short) rRec.index());
putRow(buf, rRec.rowBytes());
break;
case BTREE_PAGE_REMOVE:
RemoveRecord rmRec = (RemoveRecord) rec;
buf.putInt(rmRec.groupId());
buf.putLong(rmRec.pageId());
buf.putShort((short) rmRec.index());
buf.putShort((short) rmRec.count());
break;
case BTREE_PAGE_INNER_REPLACE:
InnerReplaceRecord<?> irRec = (InnerReplaceRecord<?>) rec;
buf.putInt(irRec.groupId());
buf.putLong(irRec.pageId());
buf.putShort((short) irRec.destinationIndex());
buf.putLong(irRec.sourcePageId());
buf.putShort((short) irRec.sourceIndex());
buf.putLong(irRec.removeId());
break;
case BTREE_FORWARD_PAGE_SPLIT:
SplitForwardPageRecord sfRec = (SplitForwardPageRecord) rec;
buf.putInt(sfRec.groupId());
buf.putLong(sfRec.pageId());
buf.putLong(sfRec.forwardId());
buf.putShort((short) sfRec.ioType());
buf.putShort((short) sfRec.ioVersion());
buf.putLong(sfRec.sourcePageId());
buf.putShort((short) sfRec.middleIndex());
buf.putShort((short) sfRec.count());
break;
case BTREE_EXISTING_PAGE_SPLIT:
SplitExistingPageRecord seRec = (SplitExistingPageRecord) rec;
buf.putInt(seRec.groupId());
buf.putLong(seRec.pageId());
buf.putShort((short) seRec.middleIndex());
buf.putLong(seRec.forwardId());
break;
case BTREE_PAGE_MERGE:
MergeRecord<?> mRec = (MergeRecord<?>) rec;
buf.putInt(mRec.groupId());
buf.putLong(mRec.pageId());
buf.putLong(mRec.parentId());
buf.putShort((short) mRec.parentIndex());
buf.putLong(mRec.rightId());
buf.put((byte) (mRec.isEmptyBranch() ? 1 : 0));
break;
case PAGES_LIST_SET_NEXT:
PagesListSetNextRecord plNextRec = (PagesListSetNextRecord) rec;
buf.putInt(plNextRec.groupId());
buf.putLong(plNextRec.pageId());
buf.putLong(plNextRec.nextPageId());
break;
case PAGES_LIST_SET_PREVIOUS:
PagesListSetPreviousRecord plPrevRec = (PagesListSetPreviousRecord) rec;
buf.putInt(plPrevRec.groupId());
buf.putLong(plPrevRec.pageId());
buf.putLong(plPrevRec.previousPageId());
break;
case PAGES_LIST_INIT_NEW_PAGE:
PagesListInitNewPageRecord plNewRec = (PagesListInitNewPageRecord) rec;
buf.putInt(plNewRec.groupId());
buf.putLong(plNewRec.pageId());
buf.putInt(plNewRec.ioType());
buf.putInt(plNewRec.ioVersion());
buf.putLong(plNewRec.newPageId());
buf.putLong(plNewRec.previousPageId());
buf.putLong(plNewRec.dataPageId());
break;
case PAGES_LIST_ADD_PAGE:
PagesListAddPageRecord plAddRec = (PagesListAddPageRecord) rec;
buf.putInt(plAddRec.groupId());
buf.putLong(plAddRec.pageId());
buf.putLong(plAddRec.dataPageId());
break;
case PAGES_LIST_REMOVE_PAGE:
PagesListRemovePageRecord plRmvRec = (PagesListRemovePageRecord) rec;
buf.putInt(plRmvRec.groupId());
buf.putLong(plRmvRec.pageId());
buf.putLong(plRmvRec.removedPageId());
break;
case BTREE_FIX_REMOVE_ID:
FixRemoveId frRec = (FixRemoveId) rec;
buf.putInt(frRec.groupId());
buf.putLong(frRec.pageId());
buf.putLong(frRec.removeId());
break;
case TRACKING_PAGE_DELTA:
TrackingPageDeltaRecord tpDelta = (TrackingPageDeltaRecord) rec;
buf.putInt(tpDelta.groupId());
buf.putLong(tpDelta.pageId());
buf.putLong(tpDelta.pageIdToMark());
buf.putLong(tpDelta.nextSnapshotTag());
buf.putLong(tpDelta.lastSuccessfulSnapshotTag());
break;
case META_PAGE_UPDATE_NEXT_SNAPSHOT_ID:
MetaPageUpdateNextSnapshotId mpUpdateNextSnapshotId = (MetaPageUpdateNextSnapshotId) rec;
buf.putInt(mpUpdateNextSnapshotId.groupId());
buf.putLong(mpUpdateNextSnapshotId.pageId());
buf.putLong(mpUpdateNextSnapshotId.nextSnapshotId());
break;
case META_PAGE_UPDATE_LAST_SUCCESSFUL_FULL_SNAPSHOT_ID:
MetaPageUpdateLastSuccessfulFullSnapshotId mpUpdateLastSuccFullSnapshotId = (MetaPageUpdateLastSuccessfulFullSnapshotId) rec;
buf.putInt(mpUpdateLastSuccFullSnapshotId.groupId());
buf.putLong(mpUpdateLastSuccFullSnapshotId.pageId());
buf.putLong(mpUpdateLastSuccFullSnapshotId.lastSuccessfulFullSnapshotId());
break;
case META_PAGE_UPDATE_LAST_SUCCESSFUL_SNAPSHOT_ID:
MetaPageUpdateLastSuccessfulSnapshotId mpUpdateLastSuccSnapshotId = (MetaPageUpdateLastSuccessfulSnapshotId) rec;
buf.putInt(mpUpdateLastSuccSnapshotId.groupId());
buf.putLong(mpUpdateLastSuccSnapshotId.pageId());
buf.putLong(mpUpdateLastSuccSnapshotId.lastSuccessfulSnapshotId());
buf.putLong(mpUpdateLastSuccSnapshotId.lastSuccessfulSnapshotTag());
break;
case META_PAGE_UPDATE_LAST_ALLOCATED_INDEX:
MetaPageUpdateLastAllocatedIndex mpUpdateLastAllocatedIdx = (MetaPageUpdateLastAllocatedIndex) rec;
buf.putInt(mpUpdateLastAllocatedIdx.groupId());
buf.putLong(mpUpdateLastAllocatedIdx.pageId());
buf.putInt(mpUpdateLastAllocatedIdx.lastAllocatedIndex());
break;
case PART_META_UPDATE_STATE:
PartitionMetaStateRecord partMetaStateRecord = (PartitionMetaStateRecord) rec;
buf.putInt(partMetaStateRecord.groupId());
buf.putInt(partMetaStateRecord.partitionId());
buf.put(partMetaStateRecord.state());
buf.putLong(0);
break;
case PAGE_LIST_META_RESET_COUNT_RECORD:
PageListMetaResetCountRecord pageListMetaResetCntRecord = (PageListMetaResetCountRecord) rec;
buf.putInt(pageListMetaResetCntRecord.groupId());
buf.putLong(pageListMetaResetCntRecord.pageId());
break;
case ROTATED_ID_PART_RECORD:
RotatedIdPartRecord rotatedIdPartRecord = (RotatedIdPartRecord) rec;
buf.putInt(rotatedIdPartRecord.groupId());
buf.putLong(rotatedIdPartRecord.pageId());
buf.put(rotatedIdPartRecord.rotatedIdPart());
break;
case TX_RECORD:
txRecordSerializer.write((TxRecord) rec, buf);
break;
case SWITCH_SEGMENT_RECORD:
break;
case MASTER_KEY_CHANGE_RECORD_V2:
MasterKeyChangeRecordV2 mkChangeRec = (MasterKeyChangeRecordV2) rec;
byte[] keyIdBytes = mkChangeRec.getMasterKeyName().getBytes();
buf.putInt(keyIdBytes.length);
buf.put(keyIdBytes);
List<T2<Integer, GroupKeyEncrypted>> grpKeys = mkChangeRec.getGrpKeys();
buf.putInt(grpKeys.size());
for (T2<Integer, GroupKeyEncrypted> entry : grpKeys) {
GroupKeyEncrypted grpKey = entry.get2();
buf.putInt(entry.get1());
buf.put((byte) grpKey.id());
buf.putInt(grpKey.key().length);
buf.put(grpKey.key());
}
break;
case REENCRYPTION_START_RECORD:
ReencryptionStartRecord statusRecord = (ReencryptionStartRecord) rec;
Map<Integer, Byte> grps = statusRecord.groups();
buf.putInt(grps.size());
for (Map.Entry<Integer, Byte> e : grps.entrySet()) {
buf.putInt(e.getKey());
buf.put(e.getValue());
}
break;
case INDEX_ROOT_PAGE_RENAME_RECORD:
((IndexRenameRootPageRecord) rec).writeRecord(buf);
break;
case PARTITION_CLEARING_START_RECORD:
PartitionClearingStartRecord partitionClearingStartRecord = (PartitionClearingStartRecord) rec;
buf.putInt(partitionClearingStartRecord.partitionId());
buf.putInt(partitionClearingStartRecord.groupId());
buf.putLong(partitionClearingStartRecord.clearVersion());
break;
default:
throw new UnsupportedOperationException("Type: " + rec.type());
}
}
use of org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord in project ignite by apache.
the class PagesList method fairMerge.
/**
* Link previous and next to each other.
* @param prevId Previous Previous page ID.
* @param pageId Page ID.
* @param nextId Next page ID.
* @param nextPage Next page absolute pointer.
* @param nextAddr Next page address.
* @throws IgniteCheckedException If failed.
*/
private void fairMerge(final long prevId, long pageId, long nextId, long nextPage, long nextAddr) throws IgniteCheckedException {
long prevPage = acquirePage(prevId);
try {
// No check, we keep a reference.
final long prevAddr = writeLock(prevId, prevPage);
assert prevAddr != 0L;
try {
PagesListNodeIO prevIO = PagesListNodeIO.VERSIONS.forPage(prevAddr);
PagesListNodeIO nextIO = PagesListNodeIO.VERSIONS.forPage(nextAddr);
// These references must be updated at the same time in write locks.
assert prevIO.getNextId(prevAddr) == pageId;
assert nextIO.getPreviousId(nextAddr) == pageId;
prevIO.setNextId(prevAddr, nextId);
if (needWalDeltaRecord(prevId, prevPage, null))
wal.log(new PagesListSetNextRecord(grpId, prevId, nextId));
nextIO.setPreviousId(nextAddr, prevId);
if (needWalDeltaRecord(nextId, nextPage, null))
wal.log(new PagesListSetPreviousRecord(grpId, nextId, prevId));
} finally {
writeUnlock(prevId, prevPage, prevAddr, true);
}
} finally {
releasePage(prevId, prevPage);
}
}
Aggregations