@Test public void createAndIteratePartitions() throws Exception { Tablespace tablespace = new Tablespace("test"); String tmpdir = Files.createTempDir().getAbsolutePath(); tablespace.setCustomDataDir(tmpdir); tablespace.loadDb(false); TableDefinition tblDef = getTableDefTimeAndValue(); RdbPartitionManager pm = new RdbPartitionManager(tablespace, "test", tblDef, 1); RdbPartition part = (RdbPartition) pm.createAndGetPartition(TimeEncoding.parse("2011-01-01T00:00:00"), 1); assertEquals("2011/001", part.dir); part = (RdbPartition) pm.createAndGetPartition(TimeEncoding.parse("2011-03-01T00:00:00"), 1); assertEquals("2011/060", part.dir); part = (RdbPartition) pm.createAndGetPartition(TimeEncoding.parse("2011-02-01T00:00:00"), 2); assertEquals("2011/032", part.dir); part = (RdbPartition) pm.createAndGetPartition(TimeEncoding.parse("2011-02-01T00:00:00"), 3); assertEquals("2011/032", part.dir); part = (RdbPartition) pm.createAndGetPartition(TimeEncoding.parse("2011-03-01T00:00:00"), 3); assertEquals("2011/060", part.dir); Set<Object> filter = new HashSet<>(); filter.add(1); filter.add(3); Iterator<List<Partition>> it = pm.iterator(TimeEncoding.parse("2011-02-01T00:00:00"), filter); assertTrue(it.hasNext()); List<Partition> parts = it.next(); assertEquals(1, parts.size()); assertTrue(it.hasNext()); parts = it.next(); assertEquals("2011/060", ((RdbPartition) parts.get(0)).dir); assertEquals("2011/060", ((RdbPartition) parts.get(1)).dir); tablespace.close(); tablespace = new Tablespace("test"); tablespace.setCustomDataDir(tmpdir); tablespace.loadDb(true); pm = new RdbPartitionManager(tablespace, "test", tblDef, 1); pm.readPartitions(); List<Partition> plist = pm.getPartitions(); assertEquals(5, plist.size()); tablespace.close(); Path path = Paths.get(tmpdir); FileUtils.deleteRecursivelyIfExists(path); }
public void readPartitions() throws RocksDBException, IOException { ColumnValueSerializer cvs = new ColumnValueSerializer(tableDefinition); for (TablespaceRecord tr : tablespace.getTablePartitions(yamcsInstance, tableDefinition.getName())) { if (tr.hasPartitionValue()) { if (tr.hasPartition()) { TimePartitionInfo pinfo = partitioningSpec.getTimePartitioningSchema() .parseDir(tr.getPartition().getPartitionDir()); if (pinfo == null) { log.warn("Cannot parse partition from {}, ignoring", tr.getPartition()); continue; } addPartitionByTimeAndValue(tr.getTbsIndex(), pinfo, cvs.byteArrayToObject(tr.getPartitionValue().toByteArray())); } else { addPartitionByValue(tr.getTbsIndex(), cvs.byteArrayToObject(tr.getPartitionValue().toByteArray())); } } else { if (tr.hasPartition()) { addPartitionByTime(tr.getTbsIndex(), tr.getPartition()); } else { addPartitionByNone(tr.getTbsIndex()); } } } for (TablespaceRecord tr : tablespace.getTableHistograms(yamcsInstance, tableDefinition.getName())) { if (tr.hasPartition()) { addHistogramByTime(tr); } else { addHistogramByNone(tr); } } }
RdbPartitionManager extends PartitionManager { public void readPartitions() throws RocksDBException, IOException { ColumnValueSerializer cvs = new ColumnValueSerializer(tableDefinition); for (TablespaceRecord tr : tablespace.getTablePartitions(yamcsInstance, tableDefinition.getName())) { if (tr.hasPartitionValue()) { if (tr.hasPartition()) { TimePartitionInfo pinfo = partitioningSpec.getTimePartitioningSchema() .parseDir(tr.getPartition().getPartitionDir()); if (pinfo == null) { log.warn("Cannot parse partition from {}, ignoring", tr.getPartition()); continue; } addPartitionByTimeAndValue(tr.getTbsIndex(), pinfo, cvs.byteArrayToObject(tr.getPartitionValue().toByteArray())); } else { addPartitionByValue(tr.getTbsIndex(), cvs.byteArrayToObject(tr.getPartitionValue().toByteArray())); } } else { if (tr.hasPartition()) { addPartitionByTime(tr.getTbsIndex(), tr.getPartition()); } else { addPartitionByNone(tr.getTbsIndex()); } } } for (TablespaceRecord tr : tablespace.getTableHistograms(yamcsInstance, tableDefinition.getName())) { if (tr.hasPartition()) { addHistogramByTime(tr); } else { addHistogramByNone(tr); } } } }
RdbPartitionManager extends PartitionManager { public void readPartitions() throws RocksDBException, IOException { ColumnValueSerializer cvs = new ColumnValueSerializer(tableDefinition); for (TablespaceRecord tr : tablespace.getTablePartitions(yamcsInstance, tableDefinition.getName())) { if (tr.hasPartitionValue()) { if (tr.hasPartition()) { TimePartitionInfo pinfo = partitioningSpec.getTimePartitioningSchema() .parseDir(tr.getPartition().getPartitionDir()); if (pinfo == null) { log.warn("Cannot parse partition from {}, ignoring", tr.getPartition()); continue; } addPartitionByTimeAndValue(tr.getTbsIndex(), pinfo, cvs.byteArrayToObject(tr.getPartitionValue().toByteArray())); } else { addPartitionByValue(tr.getTbsIndex(), cvs.byteArrayToObject(tr.getPartitionValue().toByteArray())); } } else { if (tr.hasPartition()) { addPartitionByTime(tr.getTbsIndex(), tr.getPartition()); } else { addPartitionByNone(tr.getTbsIndex()); } } } for (TablespaceRecord tr : tablespace.getTableHistograms(yamcsInstance, tableDefinition.getName())) { if (tr.hasPartition()) { addHistogramByTime(tr); } else { addHistogramByNone(tr); } } } RdbPartitionManager(Tablespace tablespace, String yamcsInstance, TableDefinition tableDefinition, int tblTbsIndex); }
RdbPartitionManager extends PartitionManager { public void readPartitions() throws RocksDBException, IOException { ColumnValueSerializer cvs = new ColumnValueSerializer(tableDefinition); for (TablespaceRecord tr : tablespace.getTablePartitions(yamcsInstance, tableDefinition.getName())) { if (tr.hasPartitionValue()) { if (tr.hasPartition()) { TimePartitionInfo pinfo = partitioningSpec.getTimePartitioningSchema() .parseDir(tr.getPartition().getPartitionDir()); if (pinfo == null) { log.warn("Cannot parse partition from {}, ignoring", tr.getPartition()); continue; } addPartitionByTimeAndValue(tr.getTbsIndex(), pinfo, cvs.byteArrayToObject(tr.getPartitionValue().toByteArray())); } else { addPartitionByValue(tr.getTbsIndex(), cvs.byteArrayToObject(tr.getPartitionValue().toByteArray())); } } else { if (tr.hasPartition()) { addPartitionByTime(tr.getTbsIndex(), tr.getPartition()); } else { addPartitionByNone(tr.getTbsIndex()); } } } for (TablespaceRecord tr : tablespace.getTableHistograms(yamcsInstance, tableDefinition.getName())) { if (tr.hasPartition()) { addHistogramByTime(tr); } else { addHistogramByNone(tr); } } } RdbPartitionManager(Tablespace tablespace, String yamcsInstance, TableDefinition tableDefinition, int tblTbsIndex); void readPartitions(); }
RdbPartitionManager extends PartitionManager { public void readPartitions() throws RocksDBException, IOException { ColumnValueSerializer cvs = new ColumnValueSerializer(tableDefinition); for (TablespaceRecord tr : tablespace.getTablePartitions(yamcsInstance, tableDefinition.getName())) { if (tr.hasPartitionValue()) { if (tr.hasPartition()) { TimePartitionInfo pinfo = partitioningSpec.getTimePartitioningSchema() .parseDir(tr.getPartition().getPartitionDir()); if (pinfo == null) { log.warn("Cannot parse partition from {}, ignoring", tr.getPartition()); continue; } addPartitionByTimeAndValue(tr.getTbsIndex(), pinfo, cvs.byteArrayToObject(tr.getPartitionValue().toByteArray())); } else { addPartitionByValue(tr.getTbsIndex(), cvs.byteArrayToObject(tr.getPartitionValue().toByteArray())); } } else { if (tr.hasPartition()) { addPartitionByTime(tr.getTbsIndex(), tr.getPartition()); } else { addPartitionByNone(tr.getTbsIndex()); } } } for (TablespaceRecord tr : tablespace.getTableHistograms(yamcsInstance, tableDefinition.getName())) { if (tr.hasPartition()) { addHistogramByTime(tr); } else { addHistogramByNone(tr); } } } RdbPartitionManager(Tablespace tablespace, String yamcsInstance, TableDefinition tableDefinition, int tblTbsIndex); void readPartitions();  }