use of org.apache.ignite.internal.processors.cache.database.RootPage in project ignite by apache.
the class MetadataStorageSelfTest method metaAllocation.
/**
* @throws Exception If failed.
*/
private void metaAllocation() throws Exception {
PageMemory mem = memory(true);
int[] cacheIds = new int[] { 1, "partitioned".hashCode(), "replicated".hashCode() };
Map<Integer, Map<String, RootPage>> allocatedIdxs = new HashMap<>();
mem.start();
try {
final Map<Integer, MetadataStorage> storeMap = new HashMap<>();
for (int i = 0; i < 1_000; i++) {
int cacheId = cacheIds[i % cacheIds.length];
Map<String, RootPage> idxMap = allocatedIdxs.get(cacheId);
if (idxMap == null) {
idxMap = new HashMap<>();
allocatedIdxs.put(cacheId, idxMap);
}
String idxName;
do {
idxName = randomName();
} while (idxMap.containsKey(idxName));
MetadataStorage metaStore = storeMap.get(cacheId);
if (metaStore == null) {
metaStore = new MetadataStorage(mem, null, new AtomicLong(), cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX, null, mem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX), true);
storeMap.put(cacheId, metaStore);
}
final RootPage rootPage = metaStore.getOrAllocateForTree(idxName);
assertTrue(rootPage.isAllocated());
idxMap.put(idxName, rootPage);
}
for (int cacheId : cacheIds) {
Map<String, RootPage> idxMap = allocatedIdxs.get(cacheId);
for (Map.Entry<String, RootPage> entry : idxMap.entrySet()) {
String idxName = entry.getKey();
FullPageId rootPageId = entry.getValue().pageId();
final RootPage rootPage = storeMap.get(cacheId).getOrAllocateForTree(idxName);
assertEquals("Invalid root page ID restored [cacheId=" + cacheId + ", idxName=" + idxName + ']', rootPageId, rootPage.pageId());
assertFalse("Root page already allocated [cacheId=" + cacheId + ", idxName=" + idxName + ']', rootPage.isAllocated());
}
}
} finally {
mem.stop();
}
}
Aggregations