Search in sources :

Example 1 with MetadataReader

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()));
        }
    }
}
Also used : MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery)

Example 2 with MetadataReader

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.");
    }
}
Also used : GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) DataStoreOperations(org.locationtech.geowave.core.store.operations.DataStoreOperations) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) MetadataType(org.locationtech.geowave.core.store.operations.MetadataType) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) Index(org.locationtech.geowave.core.store.api.Index) RowWriter(org.locationtech.geowave.core.store.operations.RowWriter) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) ReaderParamsBuilder(org.locationtech.geowave.core.store.operations.ReaderParamsBuilder) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) MetadataWriter(org.locationtech.geowave.core.store.operations.MetadataWriter) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery)

Example 3 with MetadataReader

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());
}
Also used : CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) IOException(java.io.IOException)

Example 4 with MetadataReader

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));
    }
}
Also used : ByteArray(org.locationtech.geowave.core.index.ByteArray) BiMap(com.google.common.collect.BiMap) DataStoreOperations(org.locationtech.geowave.core.store.operations.DataStoreOperations) Logger(org.slf4j.Logger) StringUtils(org.locationtech.geowave.core.index.StringUtils) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) LoggerFactory(org.slf4j.LoggerFactory) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery) Iterators(com.google.common.collect.Iterators) MetadataType(org.locationtech.geowave.core.store.operations.MetadataType) HashBiMap(com.google.common.collect.HashBiMap) MetadataWriter(org.locationtech.geowave.core.store.operations.MetadataWriter) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) CloseableIteratorWrapper(org.locationtech.geowave.core.store.CloseableIteratorWrapper) ByteArrayUtils(org.locationtech.geowave.core.index.ByteArrayUtils) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) ArrayUtils(org.apache.commons.lang.ArrayUtils) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) CloseableIteratorWrapper(org.locationtech.geowave.core.store.CloseableIteratorWrapper) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery)

Example 5 with MetadataReader

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;
}
Also used : DataStoreOperations(org.locationtech.geowave.core.store.operations.DataStoreOperations) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) ArrayList(java.util.ArrayList) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) DefaultStatisticsProvider(org.locationtech.geowave.core.store.statistics.DefaultStatisticsProvider) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) Index(org.locationtech.geowave.core.store.api.Index) ParameterException(com.beust.jcommander.ParameterException) IOException(java.io.IOException) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) Statistic(org.locationtech.geowave.core.store.api.Statistic) MetadataDeleter(org.locationtech.geowave.core.store.operations.MetadataDeleter) DataStore(org.locationtech.geowave.core.store.api.DataStore) ParameterException(com.beust.jcommander.ParameterException) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery)

Aggregations

GeoWaveMetadata (org.locationtech.geowave.core.store.entities.GeoWaveMetadata)12 MetadataReader (org.locationtech.geowave.core.store.operations.MetadataReader)12 MetadataQuery (org.locationtech.geowave.core.store.operations.MetadataQuery)10 IOException (java.io.IOException)8 DataStoreOperations (org.locationtech.geowave.core.store.operations.DataStoreOperations)5 ByteArray (org.locationtech.geowave.core.index.ByteArray)4 CloseableIterator (org.locationtech.geowave.core.store.CloseableIterator)4 InternalAdapterStore (org.locationtech.geowave.core.store.adapter.InternalAdapterStore)4 MetadataType (org.locationtech.geowave.core.store.operations.MetadataType)4 MetadataWriter (org.locationtech.geowave.core.store.operations.MetadataWriter)4 Iterators (com.google.common.collect.Iterators)3 ArrayList (java.util.ArrayList)3 CloseableIteratorWrapper (org.locationtech.geowave.core.store.CloseableIteratorWrapper)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 BiMap (com.google.common.collect.BiMap)2 HashBiMap (com.google.common.collect.HashBiMap)2 Maps (com.google.common.collect.Maps)2 ArrayUtils (org.apache.commons.lang.ArrayUtils)2 ByteArrayUtils (org.locationtech.geowave.core.index.ByteArrayUtils)2