use of org.locationtech.geowave.core.store.operations.MetadataWriter in project geowave by locationtech.
the class GeoWaveStabilityIT method copyBadData.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void copyBadData(final boolean badMetadata) throws Exception {
final DataStoreOperations badStoreOperations = badDataStore.createDataStoreOperations();
final DataStoreOperations storeOperations = dataStore.createDataStoreOperations();
final PersistentAdapterStore adapterStore = dataStore.createAdapterStore();
final InternalAdapterStore internalAdapterStore = dataStore.createInternalAdapterStore();
final AdapterIndexMappingStore indexMappingStore = dataStore.createAdapterIndexMappingStore();
final IndexStore indexStore = dataStore.createIndexStore();
for (final MetadataType metadataType : MetadataType.values()) {
try (MetadataWriter writer = badStoreOperations.createMetadataWriter(metadataType)) {
final MetadataReader reader = storeOperations.createMetadataReader(metadataType);
try (CloseableIterator<GeoWaveMetadata> it = reader.query(new MetadataQuery(null, null))) {
while (it.hasNext()) {
if (badMetadata) {
writer.write(new BadGeoWaveMetadata(it.next()));
} else {
writer.write(it.next());
}
}
}
} catch (final Exception e) {
LOGGER.error("Unable to write metadata on copy", e);
}
}
final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
for (final InternalDataAdapter<?> adapter : adapters) {
for (final AdapterToIndexMapping indexMapping : indexMappingStore.getIndicesForAdapter(adapter.getAdapterId())) {
final boolean rowMerging = BaseDataStoreUtils.isRowMerging(adapter);
final Index index = indexMapping.getIndex(indexStore);
final ReaderParamsBuilder bldr = new ReaderParamsBuilder(index, adapterStore, indexMappingStore, internalAdapterStore, GeoWaveRowIteratorTransformer.NO_OP_TRANSFORMER);
bldr.adapterIds(new short[] { adapter.getAdapterId() });
bldr.isClientsideRowMerging(rowMerging);
try (RowReader<GeoWaveRow> reader = storeOperations.createReader(bldr.build())) {
try (RowWriter writer = badStoreOperations.createWriter(index, adapter)) {
while (reader.hasNext()) {
if (!badMetadata) {
writer.write(new BadGeoWaveRow(reader.next()));
} else {
writer.write(reader.next());
}
}
}
} catch (final Exception e) {
LOGGER.error("Unable to write metadata on copy", e);
}
}
}
try {
badDataStore.createDataStatisticsStore().mergeStats();
} catch (final Exception e) {
LOGGER.info("Caught exception while merging bad stats.");
}
}
use of org.locationtech.geowave.core.store.operations.MetadataWriter in project geowave by locationtech.
the class AbstractGeoWavePersistence method addObject.
protected void addObject(final ByteArray id, final ByteArray secondaryId, final T object) {
addObjectToCache(id, secondaryId, object);
try (final MetadataWriter writer = operations.createMetadataWriter(getType())) {
if (writer != null) {
final GeoWaveMetadata metadata = new GeoWaveMetadata(id.getBytes(), secondaryId != null ? secondaryId.getBytes() : null, getVisibility(object), getValue(object));
writer.write(metadata);
}
} catch (final Exception e) {
LOGGER.warn("Unable to close metadata writer", e);
e.printStackTrace();
}
}
use of org.locationtech.geowave.core.store.operations.MetadataWriter in project geowave by locationtech.
the class BaseDataStore method copyTo.
@Override
public void copyTo(final DataStore other) {
if (other instanceof BaseDataStore) {
// efficiently copy underlying GeoWaveRow and GeoWaveMetadata
for (final MetadataType metadataType : MetadataType.values()) {
try (MetadataWriter writer = ((BaseDataStore) other).baseOperations.createMetadataWriter(metadataType)) {
final MetadataReader reader = baseOperations.createMetadataReader(metadataType);
try (CloseableIterator<GeoWaveMetadata> it = reader.query(new MetadataQuery())) {
while (it.hasNext()) {
writer.write(it.next());
}
}
} catch (final Exception e) {
LOGGER.error("Unable to write metadata on copy", e);
}
}
final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
for (final InternalDataAdapter<?> adapter : adapters) {
final AdapterToIndexMapping[] mappings = indexMappingStore.getIndicesForAdapter(adapter.getAdapterId());
for (final AdapterToIndexMapping mapping : mappings) {
final Index index = mapping.getIndex(indexStore);
final boolean rowMerging = BaseDataStoreUtils.isRowMerging(adapter);
final ReaderParamsBuilder<GeoWaveRow> bldr = new ReaderParamsBuilder<>(index, adapterStore, indexMappingStore, internalAdapterStore, rowMerging ? new GeoWaveRowMergingTransform(BaseDataStoreUtils.getRowMergingAdapter(adapter), adapter.getAdapterId()) : GeoWaveRowIteratorTransformer.NO_OP_TRANSFORMER);
bldr.adapterIds(new short[] { adapter.getAdapterId() });
bldr.isClientsideRowMerging(rowMerging);
try (RowReader<GeoWaveRow> reader = baseOperations.createReader(bldr.build())) {
try (RowWriter writer = ((BaseDataStore) other).baseOperations.createWriter(index, adapter)) {
while (reader.hasNext()) {
writer.write(reader.next());
}
}
} catch (final Exception e) {
LOGGER.error("Unable to write metadata on copy", e);
}
}
}
} else {
final DataTypeAdapter<?>[] sourceTypes = getTypes();
// add all the types that the destination store doesn't have yet
final DataTypeAdapter<?>[] destTypes = other.getTypes();
for (int i = 0; i < sourceTypes.length; i++) {
boolean found = false;
for (int k = 0; k < destTypes.length; k++) {
if (destTypes[k].getTypeName().compareTo(sourceTypes[i].getTypeName()) == 0) {
found = true;
break;
}
}
if (!found) {
other.addType(sourceTypes[i]);
}
}
// add the indices for each type
for (int i = 0; i < sourceTypes.length; i++) {
final String typeName = sourceTypes[i].getTypeName();
final short adapterId = internalAdapterStore.getAdapterId(typeName);
final AdapterToIndexMapping[] indexMappings = indexMappingStore.getIndicesForAdapter(adapterId);
final Index[] indices = Arrays.stream(indexMappings).map(mapping -> mapping.getIndex(indexStore)).toArray(Index[]::new);
other.addIndex(typeName, indices);
final QueryBuilder<?, ?> qb = QueryBuilder.newBuilder().addTypeName(typeName);
try (CloseableIterator<?> it = query(qb.build())) {
try (final Writer<Object> writer = other.createWriter(typeName)) {
while (it.hasNext()) {
writer.write(it.next());
}
}
}
}
}
}
use of org.locationtech.geowave.core.store.operations.MetadataWriter in project geowave by locationtech.
the class InternalAdapterStoreImpl method addTypeName.
// ** this introduces a distributed race condition if multiple JVM processes
// are excuting this method simultaneously
// care should be taken to either explicitly call this from a single client
// before running a distributed job, or use a distributed locking mechanism
// so that internal Adapter Ids are consistent without any race conditions
@Override
public short addTypeName(final String typeName) {
synchronized (MUTEX) {
Short adapterId = internalGetAdapterId(typeName, false);
if (adapterId != null) {
return adapterId;
}
adapterId = getInitialAdapterId(typeName);
try (final MetadataWriter writer = operations.createMetadataWriter(MetadataType.INTERNAL_ADAPTER)) {
if (writer != null) {
final byte[] adapterIdBytes = ByteArrayUtils.shortToByteArray(adapterId);
writer.write(new GeoWaveMetadata(StringUtils.stringToBinary(typeName), EXTERNAL_TO_INTERNAL_ID, null, adapterIdBytes));
writer.write(new GeoWaveMetadata(adapterIdBytes, INTERNAL_TO_EXTERNAL_ID, null, StringUtils.stringToBinary(typeName)));
}
} catch (final Exception e) {
LOGGER.warn("Unable to close metadata writer", e);
}
return adapterId;
}
}
Aggregations