use of com.ctriposs.sdb.table.AbstractMapTable in project sessdb by ppdai.
the class SDB method loadMapTables.
private void loadMapTables() throws IOException, ClassNotFoundException {
File dirFile = new File(dir);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
String[] fileNames = dirFile.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
if (filename.endsWith(AbstractMapTable.INDEX_FILE_SUFFIX))
return true;
return false;
}
});
// new DB, setup new active map table
if (fileNames == null || fileNames.length == 0) {
for (short i = 0; i < this.config.getShardNumber(); i++) {
this.activeInMemTables[i] = new HashMapTable(dir, i, LEVEL0, System.nanoTime());
this.activeInMemTables[i].markUsable(true);
// mutable
this.activeInMemTables[i].markImmutable(false);
this.activeInMemTables[i].setCompressionEnabled(this.config.isCompressionEnabled());
}
return;
}
PriorityQueue<AbstractMapTable> pq = new PriorityQueue<AbstractMapTable>();
for (String fileName : fileNames) {
int dotIndex = fileName.lastIndexOf(".");
if (dotIndex > 0) {
fileName = fileName.substring(0, dotIndex);
}
String[] parts = fileName.split("-");
Preconditions.checkArgument(parts != null && parts.length == 3, "on-disk table file names corrupted!");
int level = Integer.parseInt(parts[1]);
if (level == LEVEL0) {
pq.add(new HashMapTable(dir, fileName));
} else if (level == LEVEL1) {
pq.add(new MMFMapTable(dir, fileName));
} else {
pq.add(new FCMapTable(dir, fileName));
}
}
Preconditions.checkArgument(pq.size() > 0, "on-disk table file names corrupted!");
// setup active map table
for (int i = 0; i < this.config.getShardNumber(); i++) {
AbstractMapTable table = pq.poll();
Preconditions.checkArgument(table.getLevel() == 0, "on-disk table file names corrupted, no level 0 map tables");
this.activeInMemTables[table.getShard()] = (HashMapTable) table;
this.activeInMemTables[table.getShard()].markUsable(true);
// mutable
this.activeInMemTables[table.getShard()].markImmutable(false);
this.activeInMemTables[table.getShard()].setCompressionEnabled(this.config.isCompressionEnabled());
}
while (!pq.isEmpty()) {
AbstractMapTable table = pq.poll();
if (table.isUsable()) {
int level = table.getLevel();
LevelQueue lq = levelQueueLists[table.getShard()].get(level);
lq.addLast(table);
} else {
// garbage
table.close();
table.delete();
}
}
}
Aggregations