Search in sources :

Example 1 with RowDeleter

use of org.locationtech.geowave.core.store.operations.RowDeleter in project geowave by locationtech.

the class DataStoreUtils method mergeData.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static boolean mergeData(final DataStoreOperations operations, final Integer maxRangeDecomposition, final Index index, final PersistentAdapterStore adapterStore, final InternalAdapterStore internalAdapterStore, final AdapterIndexMappingStore adapterIndexMappingStore) {
    final RowDeleter deleter = operations.createRowDeleter(index.getName(), adapterStore, internalAdapterStore);
    try {
        final Map<Short, InternalDataAdapter> mergingAdapters = new HashMap<>();
        final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
        for (final InternalDataAdapter<?> adapter : adapters) {
            if ((adapter.getAdapter() instanceof RowMergingDataAdapter) && (((RowMergingDataAdapter) adapter.getAdapter()).getTransform() != null)) {
                mergingAdapters.put(adapter.getAdapterId(), adapter);
            }
        }
        final ReaderParamsBuilder<GeoWaveRow> paramsBuilder = new ReaderParamsBuilder<>(index, adapterStore, adapterIndexMappingStore, internalAdapterStore, GeoWaveRowIteratorTransformer.NO_OP_TRANSFORMER).isClientsideRowMerging(true).maxRangeDecomposition(maxRangeDecomposition);
        final short[] adapterIds = new short[1];
        for (final Entry<Short, InternalDataAdapter> adapter : mergingAdapters.entrySet()) {
            adapterIds[0] = adapter.getKey();
            paramsBuilder.adapterIds(adapterIds);
            try (final RowWriter writer = operations.createWriter(index, adapter.getValue());
                final RowReader<GeoWaveRow> reader = operations.createReader(paramsBuilder.build())) {
                final RewritingMergingEntryIterator<?> iterator = new RewritingMergingEntryIterator(adapterStore, adapterIndexMappingStore, index, reader, Maps.transformValues(mergingAdapters, v -> v.getAdapter()), writer, deleter);
                while (iterator.hasNext()) {
                    iterator.next();
                }
            } catch (final Exception e) {
                LOGGER.error("Exception occurred while merging data.", e);
                throw new RuntimeException(e);
            }
        }
    } finally {
        try {
            deleter.close();
        } catch (final Exception e) {
            LOGGER.warn("Exception occurred when closing deleter.", e);
        }
    }
    return true;
}
Also used : GeoWaveKeyImpl(org.locationtech.geowave.core.store.entities.GeoWaveKeyImpl) Arrays(java.util.Arrays) ParameterException(com.beust.jcommander.ParameterException) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) HierarchicalNumericIndexStrategy(org.locationtech.geowave.core.index.HierarchicalNumericIndexStrategy) FlattenedDataSet(org.locationtech.geowave.core.store.flatten.FlattenedDataSet) LoggerFactory(org.slf4j.LoggerFactory) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) RowWriter(org.locationtech.geowave.core.store.operations.RowWriter) PartitionBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.PartitionBinningStrategy) ReaderParamsBuilder(org.locationtech.geowave.core.store.operations.ReaderParamsBuilder) ByteBuffer(java.nio.ByteBuffer) FieldReader(org.locationtech.geowave.core.store.data.field.FieldReader) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery) Lists(com.clearspring.analytics.util.Lists) NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) CustomIndex(org.locationtech.geowave.core.store.index.CustomIndex) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) InternalCustomConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints.InternalCustomConstraints) Map(java.util.Map) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) GeoWaveKey(org.locationtech.geowave.core.store.entities.GeoWaveKey) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) FlattenedUnreadDataSingleRow(org.locationtech.geowave.core.store.flatten.FlattenedUnreadDataSingleRow) FlattenedFieldInfo(org.locationtech.geowave.core.store.flatten.FlattenedFieldInfo) RowReader(org.locationtech.geowave.core.store.operations.RowReader) Set(java.util.Set) UUID(java.util.UUID) DataTypeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.DataTypeBinningStrategy) List(java.util.List) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) BitmaskUtils(org.locationtech.geowave.core.store.flatten.BitmaskUtils) Entry(java.util.Map.Entry) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) RowTransform(org.locationtech.geowave.core.store.adapter.RowMergingDataAdapter.RowTransform) UnconstrainedVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.UnconstrainedVisibilityHandler) GeoWaveRowImpl(org.locationtech.geowave.core.store.entities.GeoWaveRowImpl) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy) RowRangeHistogramValue(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic.RowRangeHistogramValue) ByteArray(org.locationtech.geowave.core.index.ByteArray) IndexMetaData(org.locationtech.geowave.core.index.IndexMetaData) RowRangeHistogramStatistic(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic) StringUtils(org.locationtech.geowave.core.index.StringUtils) GeoWaveValueImpl(org.locationtech.geowave.core.store.entities.GeoWaveValueImpl) AdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.AdapterPersistenceEncoding) GeoWaveRowIteratorTransformer(org.locationtech.geowave.core.store.entities.GeoWaveRowIteratorTransformer) HashMap(java.util.HashMap) RowDeleter(org.locationtech.geowave.core.store.operations.RowDeleter) SubStrategy(org.locationtech.geowave.core.index.HierarchicalNumericIndexStrategy.SubStrategy) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) ArrayList(java.util.ArrayList) Mergeable(org.locationtech.geowave.core.index.Mergeable) HashSet(java.util.HashSet) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) MetadataType(org.locationtech.geowave.core.store.operations.MetadataType) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) VarintUtils(org.locationtech.geowave.core.index.VarintUtils) LinkedList(java.util.LinkedList) Index(org.locationtech.geowave.core.store.api.Index) MetadataDeleter(org.locationtech.geowave.core.store.operations.MetadataDeleter) GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) DataStoreOperations(org.locationtech.geowave.core.store.operations.DataStoreOperations) Logger(org.slf4j.Logger) PersistentDataset(org.locationtech.geowave.core.store.data.PersistentDataset) CommonIndexModel(org.locationtech.geowave.core.store.index.CommonIndexModel) DataStore(org.locationtech.geowave.core.store.api.DataStore) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) Maps(com.google.common.collect.Maps) File(java.io.File) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) RangeReaderParams(org.locationtech.geowave.core.store.operations.RangeReaderParams) DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) TreeMap(java.util.TreeMap) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) RowMergingDataAdapter(org.locationtech.geowave.core.store.adapter.RowMergingDataAdapter) HintKey(org.locationtech.geowave.core.store.query.options.CommonQueryOptions.HintKey) ByteArrayUtils(org.locationtech.geowave.core.index.ByteArrayUtils) CustomIndexStrategy(org.locationtech.geowave.core.index.CustomIndexStrategy) FlattenedUnreadData(org.locationtech.geowave.core.store.flatten.FlattenedUnreadData) Collections(java.util.Collections) CompositeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.CompositeBinningStrategy) RowMergingDataAdapter(org.locationtech.geowave.core.store.adapter.RowMergingDataAdapter) GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) HashMap(java.util.HashMap) RowDeleter(org.locationtech.geowave.core.store.operations.RowDeleter) RowWriter(org.locationtech.geowave.core.store.operations.RowWriter) ParameterException(com.beust.jcommander.ParameterException) ReaderParamsBuilder(org.locationtech.geowave.core.store.operations.ReaderParamsBuilder) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter)

Example 2 with RowDeleter

use of org.locationtech.geowave.core.store.operations.RowDeleter in project geowave by locationtech.

the class AccumuloOperations method createDeleter.

@Override
public <T> Deleter<T> createDeleter(final ReaderParams<T> readerParams) {
    final ScannerBase scanner = getScanner(readerParams, true);
    if (readerParams.isMixedVisibility() || (scanner == null) || !options.isServerSideLibraryEnabled()) {
        // currently scanner shouldn't be null, but in the future this could
        // be used to imply that range or bulk delete is unnecessary and we
        // instead simply delete by row ID
        // however it has been discovered the batch deletion doesn't work
        // with Accumulo's WholeRowIterator so if there are mixed
        // visibilities, meaning a single row with varying visibilities for
        // different fields we would not be assured we are properly
        // combining the visibilities of a single row without
        // WholeRowIterator so therefore we need to backup to using the
        // slower delete by row technique
        final RowDeleter rowDeleter = createRowDeleter(readerParams.getIndex().getName(), readerParams.getAdapterStore(), readerParams.getInternalAdapterStore(), readerParams.getAdditionalAuthorizations());
        if (rowDeleter != null) {
            return new QueryAndDeleteByRow<>(rowDeleter, createReader(readerParams));
        }
        return new QueryAndDeleteByRow<>();
    }
    addConstraintsScanIteratorSettings(readerParams, scanner, options);
    // removing the "novalue" iterator means the batch deleter will return
    // values which is essential to maintaining stats
    // this is applicable to accumulo versions < 1.9
    scanner.removeScanIterator(BatchDeleter.class.getName() + ".NOVALUE");
    // this is applicable to accumulo versions >= 1.9
    scanner.removeScanIterator(BatchDeleter.class.getName().replaceAll("[.]", "_") + "_NOVALUE");
    return new AccumuloDeleter<>((BatchDeleter) scanner, getClientSideFilterRanges(readerParams), readerParams.getRowTransformer(), readerParams.getIndex().getIndexStrategy().getPartitionKeyLength(), readerParams.isMixedVisibility() && !readerParams.isServersideAggregation(), readerParams.isClientsideRowMerging(), true);
}
Also used : BatchDeleter(org.apache.accumulo.core.client.BatchDeleter) QueryAndDeleteByRow(org.locationtech.geowave.core.store.operations.QueryAndDeleteByRow) ScannerBase(org.apache.accumulo.core.client.ScannerBase) RowDeleter(org.locationtech.geowave.core.store.operations.RowDeleter)

Example 3 with RowDeleter

use of org.locationtech.geowave.core.store.operations.RowDeleter in project geowave by locationtech.

the class HBaseOperations method deleteAll.

@Override
public boolean deleteAll(final String indexName, final String typeName, final Short adapterId, final String... additionalAuthorizations) {
    RowDeleter deleter = null;
    Iterable<Result> scanner = null;
    try {
        deleter = createRowDeleter(indexName, // these params aren't needed for hbase
        null, null, additionalAuthorizations);
        Index index = null;
        try (final CloseableIterator<GeoWaveMetadata> it = createMetadataReader(MetadataType.INDEX).query(new MetadataQuery(StringUtils.stringToBinary(indexName), null, additionalAuthorizations))) {
            if (!it.hasNext()) {
                LOGGER.warn("Unable to find index to delete");
                return false;
            }
            final GeoWaveMetadata indexMd = it.next();
            index = (Index) URLClassloaderUtils.fromBinary(indexMd.getValue());
        }
        final Scan scan = new Scan();
        scan.addFamily(StringUtils.stringToBinary(ByteArrayUtils.shortToString(adapterId)));
        scanner = getScannedResults(scan, indexName);
        for (final Result result : scanner) {
            deleter.delete(new HBaseRow(result, index.getIndexStrategy().getPartitionKeyLength()));
        }
        return true;
    } catch (final Exception e) {
        LOGGER.warn("Unable to close deleter", e);
    } finally {
        if ((scanner != null) && (scanner instanceof ResultScanner)) {
            ((ResultScanner) scanner).close();
        }
        if (deleter != null) {
            try {
                deleter.close();
            } catch (final Exception e) {
                LOGGER.warn("Unable to close deleter", e);
            }
        }
    }
    return false;
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) HBaseRow(org.locationtech.geowave.datastore.hbase.HBaseRow) Index(org.locationtech.geowave.core.store.api.Index) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) Scan(org.apache.hadoop.hbase.client.Scan) RowDeleter(org.locationtech.geowave.core.store.operations.RowDeleter) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) RegionException(org.apache.hadoop.hbase.RegionException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) Result(org.apache.hadoop.hbase.client.Result) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery)

Aggregations

RowDeleter (org.locationtech.geowave.core.store.operations.RowDeleter)2 ParameterException (com.beust.jcommander.ParameterException)1 Lists (com.clearspring.analytics.util.Lists)1 Maps (com.google.common.collect.Maps)1 File (java.io.File)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1