use of org.locationtech.geowave.core.index.CompoundIndexStrategy in project geowave by locationtech.
the class CompoundHierarchicalIndexStrategyWrapper method fromBinary.
@Override
public void fromBinary(final byte[] bytes) {
final CompoundIndexStrategy rootStrategy = (CompoundIndexStrategy) PersistenceUtils.fromBinary(bytes);
parentStrategies = new ArrayList<>();
// discover hierarchy
firstHierarchicalStrategy = findHierarchicalStrategy(rootStrategy, parentStrategies);
}
use of org.locationtech.geowave.core.index.CompoundIndexStrategy in project geowave by locationtech.
the class CompoundHierarchicalIndexStrategyWrapper method getSubStrategies.
@Override
public SubStrategy[] getSubStrategies() {
// for these substrategies we need to replace the last parent strategy's
// hierarchical index strategy with the underlying substrategy index
// strategy
final SubStrategy[] subStrategies = firstHierarchicalStrategy.getSubStrategies();
final SubStrategy[] retVal = new SubStrategy[subStrategies.length];
for (int i = 0; i < subStrategies.length; i++) {
NumericIndexStrategy currentStrategyToBeReplaced = firstHierarchicalStrategy;
NumericIndexStrategy currentStrategyReplacement = subStrategies[i].getIndexStrategy();
for (int j = parentStrategies.size() - 1; j >= 0; j--) {
// traverse parents in reverse order
final CompoundIndexStrategy parent = parentStrategies.get(j);
if (parent.getPrimarySubStrategy().equals(currentStrategyToBeReplaced)) {
// replace primary
currentStrategyReplacement = new CompoundIndexStrategy(currentStrategyReplacement, parent.getSecondarySubStrategy());
} else {
// replace secondary
currentStrategyReplacement = new CompoundIndexStrategy(parent.getPrimarySubStrategy(), currentStrategyReplacement);
}
currentStrategyToBeReplaced = parent;
}
retVal[i] = new SubStrategy(currentStrategyReplacement, subStrategies[i].getPrefix());
}
return retVal;
}
use of org.locationtech.geowave.core.index.CompoundIndexStrategy in project geowave by locationtech.
the class HashKeyIndexStrategyTest method testBinaryEncoding.
@Test
public void testBinaryEncoding() {
final byte[] bytes = PersistenceUtils.toBinary(compoundIndexStrategy);
final CompoundIndexStrategy deserializedStrategy = (CompoundIndexStrategy) PersistenceUtils.fromBinary(bytes);
final byte[] bytes2 = PersistenceUtils.toBinary(deserializedStrategy);
Assert.assertArrayEquals(bytes, bytes2);
}
use of org.locationtech.geowave.core.index.CompoundIndexStrategy in project geowave by locationtech.
the class RoundRobinKeyIndexStrategyTest method testBinaryEncoding.
@Test
public void testBinaryEncoding() {
final byte[] bytes = PersistenceUtils.toBinary(compoundIndexStrategy);
final CompoundIndexStrategy deserializedStrategy = (CompoundIndexStrategy) PersistenceUtils.fromBinary(bytes);
final byte[] bytes2 = PersistenceUtils.toBinary(deserializedStrategy);
Assert.assertArrayEquals(bytes, bytes2);
}
use of org.locationtech.geowave.core.index.CompoundIndexStrategy in project geowave by locationtech.
the class RocksDBLockfileTest method testLockfile.
private void testLockfile(final int numThreads, final boolean secondaryIndexing) {
final RocksDBOptions options = new RocksDBOptions();
options.setDirectory(DEFAULT_DB_DIRECTORY);
options.getStoreOptions().setSecondaryIndexing(secondaryIndexing);
final DataStore store = new RocksDBStoreFactoryFamily().getDataStoreFactory().createStore(options);
store.deleteAll();
store.addType(BasicDataTypeAdapter.newAdapter(POI_TYPE_NAME, POI.class, "name"));
Index index = AttributeDimensionalityTypeProvider.createIndexFromOptions(store, new AttributeIndexOptions(POI_TYPE_NAME, "latitude"));
index = new CustomNameIndex(new CompoundIndexStrategy(new RoundRobinKeyIndexStrategy(32), index.getIndexStrategy()), index.getIndexModel(), index.getName() + "_" + PartitionStrategy.ROUND_ROBIN.name() + "_" + 32);
final Index latAttributeIndex = new IndexWrapper(index);
store.addIndex(POI_TYPE_NAME, latAttributeIndex);
final DataStore store2 = new RocksDBStoreFactoryFamily().getDataStoreFactory().createStore(options);
IntStream.range(0, numThreads).mapToObj(i -> CompletableFuture.runAsync(() -> {
double offset = i * numThreads;
try (Writer<POI> w = store.createWriter(POI_TYPE_NAME)) {
w.write(new POI("name" + offset, offset, offset));
}
try (CloseableIterator<POI> poiIt = store2.query(QueryBuilder.newBuilder(POI.class).build())) {
if (numThreads == 1) {
Assert.assertEquals(1, Iterators.size(poiIt));
} else {
Assert.assertTrue(Iterators.size(poiIt) >= 1);
}
}
offset++;
try (Writer<POI> w = store2.createWriter(POI_TYPE_NAME)) {
w.write(new POI("name" + offset, offset, offset));
}
try (CloseableIterator<POI> poiIt = store.query(QueryBuilder.newBuilder(POI.class).build())) {
if (numThreads == 1) {
Assert.assertEquals(2, Iterators.size(poiIt));
} else {
Assert.assertTrue(Iterators.size(poiIt) >= 2);
}
}
offset++;
try (Writer<POI> w = store2.createWriter(POI_TYPE_NAME)) {
w.write(new POI("name" + offset, offset, offset));
try (CloseableIterator<POI> poiIt = store.query(QueryBuilder.newBuilder(POI.class).build())) {
if (numThreads == 1) {
Assert.assertEquals(2, Iterators.size(poiIt));
} else {
Assert.assertTrue(Iterators.size(poiIt) >= 2);
}
}
w.flush();
try (CloseableIterator<POI> poiIt = store.query(QueryBuilder.newBuilder(POI.class).build())) {
if (numThreads == 1) {
Assert.assertEquals(3, Iterators.size(poiIt));
} else {
Assert.assertTrue(Iterators.size(poiIt) >= 3);
}
}
}
try (CloseableIterator<POI> poiIt = store2.query(QueryBuilder.newBuilder(POI.class).build())) {
if (numThreads == 1) {
Assert.assertEquals(3, Iterators.size(poiIt));
} else {
Assert.assertTrue(Iterators.size(poiIt) >= 3);
}
}
}));
store.deleteAll();
}
Aggregations