use of org.locationtech.geowave.core.store.operations.MetadataReader in project geowave by locationtech.
the class DataStoreUtils method safeMetadataDelete.
public static void safeMetadataDelete(final MetadataDeleter deleter, final DataStoreOperations operations, final MetadataType metadataType, final MetadataQuery query) {
// we need to respect visibilities although this may be much slower
final MetadataReader reader = operations.createMetadataReader(metadataType);
try (final CloseableIterator<GeoWaveMetadata> it = reader.query(query)) {
while (it.hasNext()) {
final GeoWaveMetadata entry = it.next();
deleter.delete(new MetadataQuery(entry.getPrimaryId(), entry.getSecondaryId(), query.getAuthorizations()));
}
}
}
use of org.locationtech.geowave.core.store.operations.MetadataReader 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.MetadataReader in project geowave by locationtech.
the class AbstractGeoWavePersistence method internalGetObjects.
protected CloseableIterator<T> internalGetObjects(final MetadataQuery query) {
try {
if (!operations.metadataExists(getType())) {
return new CloseableIterator.Empty<>();
}
} catch (final IOException e1) {
LOGGER.error("Unable to check for existence of metadata to get objects", e1);
return new CloseableIterator.Empty<>();
}
final MetadataReader reader = operations.createMetadataReader(getType());
final CloseableIterator<GeoWaveMetadata> it = reader.query(query);
return new NativeIteratorWrapper(it, query.getAuthorizations());
}
use of org.locationtech.geowave.core.store.operations.MetadataReader in project geowave by locationtech.
the class InternalAdapterStoreImpl method getAdapterIds.
@Override
public short[] getAdapterIds() {
final MetadataReader reader = getReader(false);
if (reader == null) {
return new short[0];
}
final CloseableIterator<GeoWaveMetadata> results = reader.query(new MetadataQuery(EXTERNAL_TO_INTERNAL_ID));
try (CloseableIterator<Short> it = new CloseableIteratorWrapper<>(results, Iterators.transform(results, input -> ByteArrayUtils.byteArrayToShort(input.getValue())))) {
return ArrayUtils.toPrimitive(Iterators.toArray(it, Short.class));
}
}
use of org.locationtech.geowave.core.store.operations.MetadataReader in project geowave by locationtech.
the class RecalculateStatsCommand method performStatsCommand.
@Override
protected boolean performStatsCommand(final DataStorePluginOptions storeOptions, final StatsCommandLineOptions statsOptions, final Console console) throws IOException {
final DataStore dataStore = storeOptions.createDataStore();
final DataStatisticsStore statStore = storeOptions.createDataStatisticsStore();
final IndexStore indexStore = storeOptions.createIndexStore();
if (all) {
// check for legacy stats table and if it exists, delete it and add all default stats
final DataStoreOperations ops = storeOptions.createDataStoreOperations();
final MetadataReader reader = ops.createMetadataReader(MetadataType.LEGACY_STATISTICS);
boolean legacyStatsExists;
// implementation to check for at least one row
try (CloseableIterator<GeoWaveMetadata> it = reader.query(new MetadataQuery(null, null))) {
legacyStatsExists = it.hasNext();
}
if (legacyStatsExists) {
console.println("Found legacy stats prior to v1.3. Deleting and recalculating all default stats as a migration to v" + VersionUtils.getVersion() + ".");
// first let's do the add just to make sure things are in working order prior to deleting
// legacy stats
console.println("Adding default statistics...");
final List<Statistic<?>> defaultStatistics = new ArrayList<>();
for (final Index index : dataStore.getIndices()) {
if (index instanceof DefaultStatisticsProvider) {
defaultStatistics.addAll(((DefaultStatisticsProvider) index).getDefaultStatistics());
}
}
for (final DataTypeAdapter<?> adapter : dataStore.getTypes()) {
final DefaultStatisticsProvider defaultStatProvider = BaseDataStoreUtils.getDefaultStatisticsProvider(adapter);
if (defaultStatProvider != null) {
defaultStatistics.addAll(defaultStatProvider.getDefaultStatistics());
}
}
dataStore.addEmptyStatistic(defaultStatistics.toArray(new Statistic[defaultStatistics.size()]));
console.println("Deleting legacy statistics...");
try (MetadataDeleter deleter = ops.createMetadataDeleter(MetadataType.LEGACY_STATISTICS)) {
deleter.delete(new MetadataQuery(null, null));
} catch (final Exception e) {
LOGGER.warn("Error deleting legacy statistics", e);
}
// Clear out all options so that all stats get recalculated.
statsOptions.setIndexName(null);
statsOptions.setTypeName(null);
statsOptions.setFieldName(null);
statsOptions.setStatType(null);
statsOptions.setTag(null);
}
}
final List<Statistic<? extends StatisticValue<?>>> toRecalculate = statsOptions.resolveMatchingStatistics(dataStore, statStore, indexStore);
if (toRecalculate.isEmpty()) {
throw new ParameterException("A matching statistic could not be found");
} else if ((toRecalculate.size() > 1) && !all) {
throw new ParameterException("Multiple statistics matched the given parameters. If this is intentional, " + "supply the --all option, otherwise provide additional parameters to " + "specify which statistic to recalculate.");
}
final Statistic<?>[] toRecalcArray = toRecalculate.toArray(new Statistic<?>[toRecalculate.size()]);
dataStore.recalcStatistic(toRecalcArray);
console.println(toRecalculate.size() + " statistic" + (toRecalculate.size() == 1 ? " was" : "s were") + " successfully recalculated.");
return true;
}
Aggregations