@Override public void shutdownIndexes() throws JasDBStorageException { LOG.info("Shutting down {} indexes", indexes.size()); for(String bagName : indexes.keySet()) { for(Index index : indexes.get(bagName).values()) { LOG.debug("Closing index: {} on bag: {}", index.getKeyInfo().getKeyName(), bagName); index.close(); } } indexes.clear(); }
public static boolean isAnyDataPresent(IndexableItem sEntity, Index index) { for(String indexField : index.getKeyInfo().getKeyFields()) { if(sEntity.hasValue(indexField)) { return true; } } return false; }
private synchronized void loadIndexes(final String bagName) throws JasDBStorageException { LOG.debug("Loading indexes for bag: {}", bagName); if(!indexes.containsKey(bagName)) { Bag bag = metadataStore.getBag(instanceId, bagName); if(bag != null) { Set<IndexDefinition> indexDefinitions = new HashSet<>(bag.getIndexDefinitions()); LOG.info("Found {} potential indexes for bag: {}", indexDefinitions.size(), bagName); Map<String, Index> bagIndexes = new HashMap<>(); for(IndexDefinition indexDefinition : indexDefinitions) { Index index = loadIndex(bagName, indexDefinition); bagIndexes.put(index.getKeyInfo().getKeyName(), index); } this.indexes.put(bagName, bagIndexes); } } }
public static void doIndexInsert(Set<Key> keys, Index index) throws JasDBStorageException { LOG.trace("Inserting {} keys into index: {}", keys.size(), index.getKeyInfo().getKeyName()); StatRecord indexInsert = StatisticsMonitor.createRecord("bag:indexInsert"); for(Key key : keys) { index.insertIntoIndex(key); } indexInsert.stop(); }
private Set<SearchCondition> getSearchConditions(BlockOperation blockOperation, Index index) { KeyInfo keyInfo = index.getKeyInfo(); return blockOperation.getConditions(keyInfo.getKeyNameMapper(), keyInfo.getKeyFields()); } }
public static Set<Key> createEntityKeys(Entity entity, Index index) throws JasDBStorageException { StatRecord createKey = StatisticsMonitor.createRecord("bag:createKey"); KeyFactory keyFactory = index.getKeyInfo().getKeyFactory(); Set<Key> insertKeys; if(keyFactory.isMultiValueKey(entity)) { insertKeys = keyFactory.createMultivalueKeys(entity); } else { insertKeys = new HashSet<>(); insertKeys.add(keyFactory.createKey(entity)); } createKey.stop(); return insertKeys; }
@Override public void removeIndex(String bagName, String keyName) throws JasDBStorageException { Index index = getIndex(bagName, keyName); if(index != null) { Map<String, Index> bagIndexes = indexes.get(bagName); bagIndexes.remove(keyName); KeyInfo keyInfo = index.getKeyInfo(); IndexDefinition definition = new IndexDefinition(keyInfo.getKeyName(), keyInfo.keyAsHeader(), keyInfo.valueAsHeader(), index.getIndexType()); metadataStore.removeBagIndex(instanceId, bagName, definition); index.removeIndex(); } else { throw new JasDBStorageException("Could not remove index, does not exist"); } }
private RestEntity loadIndexes(String instanceId, String bagName) throws JasDBException { IndexManager indexManager = getIndexManager(instanceId); StatRecord getIndexCounter = StatisticsMonitor.createRecord("getIndexes"); Map<String, Index> indexes = indexManager.getIndexes(bagName); getIndexCounter.stop(); List<IndexEntry> indexEntries = new ArrayList<>(indexes.size()); for(Index index : indexes.values()) { KeyInfo keyInfo = index.getKeyInfo(); IndexEntry entry = new IndexEntry(keyInfo.getKeyName(), keyInfo.keyAsHeader(), keyInfo.valueAsHeader(), index.hasUniqueConstraint(), index.getIndexType()); entry.setMemorySize(index.getMemoryManager().getTotalMemoryUsage()); indexEntries.add(entry); } return new IndexCollection(indexEntries); }
private void initializeIndex(Index index) throws JasDBStorageException { KeyInfo keyInfo = index.getKeyInfo(); IndexDefinition definition = new IndexDefinition(keyInfo.getKeyName(), keyInfo.keyAsHeader(), keyInfo.valueAsHeader(), index.getIndexType()); if(metadataStore.containsIndex(instanceId, bagName, definition)) { try { indexRebuilder.submit(new IndexScanAndRecovery(index, getRecordWriter().readAllRecords(), true)).get(); } catch(ExecutionException | InterruptedException e) { throw new JasDBStorageException("Unable to initialize index, index rebuild failed", e); } } else { throw new JasDBStorageException("Cannot initialize index, does not exist in store"); } }
remainingFields.removeAll(bestIndexMatch.getKeyInfo().getKeyFields());