use of co.cask.cdap.data2.metadata.dataset.Metadata in project cdap by caskdata.
the class MetadataDataset method deleteIndexes.
/**
* Deletes all indexes associated with a metadata key
*
* @param targetId the {@link NamespacedEntityId} for which keys are to be removed
* @param metadataKey the key to remove from the metadata of the specified {@link NamespacedEntityId}
*/
private void deleteIndexes(NamespacedEntityId targetId, String metadataKey) {
MDSKey mdsKey = MdsKey.getMDSIndexKey(targetId, metadataKey, null);
byte[] startKey = mdsKey.getKey();
byte[] stopKey = Bytes.stopKeyForPrefix(startKey);
try (Scanner scan = indexedTable.scan(startKey, stopKey)) {
Row next;
while ((next = scan.next()) != null) {
deleteIndexRow(next);
}
}
}
use of co.cask.cdap.data2.metadata.dataset.Metadata in project cdap by caskdata.
the class MetadataDataset method write.
private void write(NamespacedEntityId targetId, MetadataEntry entry, Set<Indexer> indexers) {
String key = entry.getKey();
MDSKey mdsValueKey = MdsKey.getMDSValueKey(targetId, key);
Put put = new Put(mdsValueKey.getKey());
// add the metadata value
put.add(Bytes.toBytes(VALUE_COLUMN), Bytes.toBytes(entry.getValue()));
indexedTable.put(put);
storeIndexes(targetId, key, indexers, entry);
writeHistory(targetId);
}
use of co.cask.cdap.data2.metadata.dataset.Metadata in project cdap by caskdata.
the class MetadataDataset method getIndexPut.
/**
* Creates a {@link Put} for the a metadata index
*
* @param targetId the {@link NamespacedEntityId} from which the metadata index has to be created
* @param metadataKey the key of the metadata entry
* @param index the index for this metadata
* @param indexColumn the column to store the index in. This column should exist in the
* {@link IndexedTable#INDEX_COLUMNS_CONF_KEY} property in the dataset's definition
* @return {@link Put} which is a index row with the value to be indexed in the #indexColumn
*/
private Put getIndexPut(NamespacedEntityId targetId, String metadataKey, String index, String indexColumn) {
MDSKey mdsIndexKey = MdsKey.getMDSIndexKey(targetId, metadataKey, index.toLowerCase());
String namespacedIndex = targetId.getNamespace() + KEYVALUE_SEPARATOR + index.toLowerCase();
Put put = new Put(mdsIndexKey.getKey());
put.add(Bytes.toBytes(indexColumn), Bytes.toBytes(namespacedIndex));
return put;
}
use of co.cask.cdap.data2.metadata.dataset.Metadata in project cdap by caskdata.
the class MetadataDataset method storeIndexes.
/**
* Store indexes for a {@link MetadataEntry}
*
* @param targetId the {@link NamespacedEntityId} from which the metadata indexes has to be stored
* @param metadataKey the metadata key for which the indexes are to be stored
* @param indexers {@link Set<String>} of {@link Indexer indexers} for this {@link MetadataEntry}
* @param metadataEntry {@link MetadataEntry} for which indexes are to be stored
*/
private void storeIndexes(NamespacedEntityId targetId, String metadataKey, Set<Indexer> indexers, MetadataEntry metadataEntry) {
// Delete existing indexes for targetId-key
deleteIndexes(targetId, metadataKey);
for (Indexer indexer : indexers) {
Set<String> indexes = indexer.getIndexes(metadataEntry);
String indexColumn = getIndexColumn(metadataKey, indexer.getSortOrder());
for (String index : indexes) {
// store just the index value
indexedTable.put(getIndexPut(targetId, metadataKey, index, indexColumn));
}
}
}
use of co.cask.cdap.data2.metadata.dataset.Metadata in project cdap by caskdata.
the class AbstractSystemMetadataWriterTest method setup.
@BeforeClass
public static void setup() throws IOException {
CConfiguration cConf = CConfiguration.create();
Injector injector = Guice.createInjector(new ConfigModule(cConf), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), Modules.override(new DataSetsModules().getInMemoryModules()).with(new AbstractModule() {
@Override
protected void configure() {
// Need the distributed metadata store.
bind(MetadataStore.class).to(DefaultMetadataStore.class);
}
}), new LocationRuntimeModule().getInMemoryModules(), new TransactionInMemoryModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new NamespaceClientRuntimeModule().getInMemoryModules());
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
store = injector.getInstance(MetadataStore.class);
}
Aggregations