@Override public void setLastUpdated(DateTime lastUpdated) { if (lastUpdated == null) { keyValueStore.remove(lastUpdatedKey); } else { keyValueStore.put(lastUpdatedKey, lastUpdated.toString()); } }
/** * Update the cardinality count. */ private void refreshCardinality() { keyValueStore.put(DimensionStoreKeyUtils.getCardinalityKey(), Integer.toString(findAllDimensionRows().size())); }
/** * This method updates the set of values corresponding to a dimension. * <p> * Eg: For dimension dim1 there were 3 rows with ID's v1, v2, v3 and DESC's value1, value2, value3 respectively * the keyValueStore would look like * all_values_key -> [id_v1_row_key, id_v2_row_key, id_v3_row_key] * <p> * After this refreshIndexForDimensionKey call, given a new row id: id_v4_row_key, it would look like * all_values_key -> [id_v1_row_key, id_v2_row_key, id_v3_row_key, id_v4_row_key] * <p> * This is useful to list all values for <blah>/dim1/values endpoint * * @param rowId The row id to be added */ private void refreshIndexForDimensionKey(String rowId) { try { String allValuesKey = DimensionStoreKeyUtils.getAllValuesKey(); String dimensionRows = keyValueStore.get(allValuesKey); Set<String> dimensionRowsSet = new LinkedHashSet<>(); if (dimensionRows != null) { dimensionRowsSet.addAll(Arrays.asList(objectMapper.readValue(dimensionRows, String[].class))); } dimensionRowsSet.add(rowId); String dimRows = objectMapper.writeValueAsString(dimensionRowsSet); keyValueStore.put(allValuesKey, dimRows); } catch (IOException e) { LOG.error("Exception while adding dimension entry in KeyValueStore : {}", e); throw new RuntimeException(e); } }
/** * Update the cardinality count. * <p> * Note that this method acquires a read lock to query the lucene index for the number of documents. */ private void refreshCardinality() { int numDocs; initializeIndexSearcher(); lock.readLock().lock(); try { numDocs = luceneIndexSearcher.getIndexReader().numDocs(); } finally { lock.readLock().unlock(); } keyValueStore.put( DimensionStoreKeyUtils.getCardinalityKey(), Integer.toString(numDocs) ); }
@Override public void setKeyValueStore(KeyValueStore keyValueStore) { this.keyValueStore = keyValueStore; // Check initialization for the cardinality in a keyValueStore if (keyValueStore.get(DimensionStoreKeyUtils.getCardinalityKey()) == null) { keyValueStore.put(DimensionStoreKeyUtils.getCardinalityKey(), "0"); } //Check Dimension value keys availability String allValuesKey = DimensionStoreKeyUtils.getAllValuesKey(); if (keyValueStore.get(allValuesKey) == null) { keyValueStore.put(allValuesKey, "[]"); } }
/** * Internal method for cleaning the dimension rows. */ public void deleteAllDimensionRows() { try { String dimRowIndexes = keyValueStore.get(DimensionStoreKeyUtils.getAllValuesKey()); if (dimRowIndexes == null) { return; } String[] keys = objectMapper.readValue(dimRowIndexes, String[].class); LinkedHashSet<String> dimRowKeys = new LinkedHashSet<>(Arrays.asList(keys)); for (String dimRowKey : dimRowKeys) { keyValueStore.remove(dimRowKey); } searchProvider.setKeyValueStore(keyValueStore); // Reset cardinality to 0 keyValueStore.put(DimensionStoreKeyUtils.getCardinalityKey(), "0"); // Reset list to empty String allValuesKey = DimensionStoreKeyUtils.getAllValuesKey(); keyValueStore.put(allValuesKey, "[]"); } catch (IOException e) { LOG.error("Exception while reading dimension rows {}", e); throw new RuntimeException(e); } }
@Override public void clearDimension() { //Remove all dimension data from the store. findAllDimensionRows().stream() .flatMap(dimensionRow -> dimensionRow.entrySet().stream()) .map(entry -> DimensionStoreKeyUtils.getRowKey(entry.getKey().getName(), entry.getValue())) .forEach(keyValueStore::remove); //Since the indices are being dropped, the dimension field stored via the columnKey is becoming stale. keyValueStore.remove(DimensionStoreKeyUtils.getColumnKey(dimension.getKey().getName())); // The allValues key mapping needs to reflect the fact that we are dropping all dimension data. keyValueStore.put(DimensionStoreKeyUtils.getAllValuesKey(), "[]"); //We're resetting the keyValueStore, so we don't want any stale last updated date floating around. keyValueStore.remove(DimensionStoreKeyUtils.getLastUpdatedKey()); refreshCardinality(); }
keyValueStore.put(DimensionStoreKeyUtils.getAllValuesKey(), "[]");