private String getMonitorKey(LuceneIndex index) { return index.getRegionPath() + "_" + index.getName(); }
public void beforeRegionDestroyed(Region region) { List<LuceneIndex> indexes = getIndexes(region.getFullPath()); if (!indexes.isEmpty()) { String indexNames = indexes.stream().map(i -> i.getName()).collect(Collectors.joining(",")); throw new IllegalStateException( String.format( "Region %s cannot be destroyed because it defines Lucene index(es) [%s]. Destroy all Lucene indexes before destroying the region.", region.getFullPath(), indexNames)); } }
private void removeFromIndexMap(LuceneIndex index) { indexMap.remove(getUniqueIndexName(index.getName(), index.getRegionPath())); }
private void registerIndex(LuceneIndex index) { String regionAndIndex = getUniqueIndexName(index.getName(), index.getRegionPath()); if (hasIndexBeenDestroyed(regionAndIndex)) { ((InternalLuceneIndex) index).destroy(true); throw new LuceneIndexDestroyedException(index.getName(), index.getRegionPath()); } else { if (!indexMap.containsKey(regionAndIndex)) { indexMap.put(regionAndIndex, index); } definedIndexMap.remove(regionAndIndex); } }
protected void destroyIndexes(String regionPath, boolean initiator) { if (!regionPath.startsWith("/")) { regionPath = "/" + regionPath; } List<LuceneIndexImpl> indexesToDestroy = new ArrayList<>(); for (LuceneIndex index : getAllIndexes()) { if (index.getRegionPath().equals(regionPath)) { LuceneIndexImpl indexImpl = (LuceneIndexImpl) index; indexImpl.destroy(initiator); indexesToDestroy.add(indexImpl); } } // If list is empty throw an exception; otherwise iterate and destroy the defined index if (indexesToDestroy.isEmpty()) { throw new IllegalArgumentException( String.format("No Lucene indexes were found in region %s", regionPath)); } else { for (LuceneIndex index : indexesToDestroy) { removeFromIndexMap(index); logger.info(String.format("Destroyed Lucene index %s from %s region %s", index.getName(), "initialized", regionPath)); } } }
protected LuceneIndexMetrics getIndexMetrics(LuceneIndex index) { int queryExecutions = getStatistic(StatsKey.QUERIES).intValue(); long queryExecutionTime = getStatistic(StatsKey.QUERY_TIME).longValue(); long queryRateAverageLatencyValue = this.queryRateAverageLatency.getAverageLatency(); int queryExecutionsInProgress = getStatistic(StatsKey.QUERIES_IN_PROGRESS).intValue(); long queryExecutionTotalHits = getStatistic(StatsKey.QUERIES_TOTAL_HITS).longValue(); int updates = getStatistic(StatsKey.UPDATES).intValue(); long updateTime = getStatistic(StatsKey.UPDATE_TIME).longValue(); long updateRateAverageLatencyValue = this.updateRateAverageLatency.getAverageLatency(); int updatesInProgress = getStatistic(StatsKey.UPDATES_IN_PROGRESS).intValue(); int commits = getStatistic(StatsKey.COMMITS).intValue(); long commitTime = getStatistic(StatsKey.COMMIT_TIME).longValue(); long commitRateAverageLatencyValue = this.commitRateAverageLatency.getAverageLatency(); int commitsInProgress = getStatistic(StatsKey.COMMITS_IN_PROGRESS).intValue(); int documents = getStatistic(StatsKey.DOCUMENTS).intValue(); return new LuceneIndexMetrics(index.getRegionPath(), index.getName(), queryExecutions, queryExecutionTime, queryRateAverageLatencyValue, queryExecutionsInProgress, queryExecutionTotalHits, updates, updateTime, updateRateAverageLatencyValue, updatesInProgress, commits, commitTime, commitRateAverageLatencyValue, commitsInProgress, documents); } }
public LuceneIndexStatsMonitor(LuceneIndex index) { super(LUCENE_SERVICE_MXBEAN_MONITOR_PREFIX + index.getRegionPath() + "_" + index.getName()); addStatisticsToMonitor(((LuceneIndexImpl) index).getIndexStats().getStats()); configureMetrics(); }
/** * Resolves the name of the {@link LuceneIndex} required in the Lucene data access, query operations * when a {@link LuceneIndex} is not specifically provided. * * @return the name of the resolve {@link LuceneIndex}. * @throws IllegalStateException if the name of the {@link LuceneIndex} cannot be resolved. * @see org.apache.geode.cache.lucene.LuceneIndex#getName() * @see #getIndexName() * @see #getLuceneIndex() */ protected String resolveIndexName() { String resolvedIndexName = Optional.ofNullable(getIndexName()) .orElseGet(() -> safeGetValue(() -> getLuceneIndex().getName())); Assert.state(StringUtils.hasText(resolvedIndexName), "The name of the Lucene Index could not be resolved"); return resolvedIndexName; }
/** * Resolves the name of the {@link LuceneIndex} required in the Lucene data access, query operations * when a {@link LuceneIndex} is not specifically provided. * * @return the name of the resolve {@link LuceneIndex}. * @throws IllegalStateException if the name of the {@link LuceneIndex} cannot be resolved. * @see org.apache.geode.cache.lucene.LuceneIndex#getName() * @see #getIndexName() * @see #getLuceneIndex() */ protected String resolveIndexName() { String resolvedIndexName = Optional.ofNullable(getIndexName()) .orElseGet(() -> safeGetValue(() -> getLuceneIndex().getName())); Assert.state(StringUtils.hasText(resolvedIndexName), "The name of the Lucene Index could not be resolved"); return resolvedIndexName; }
when(mockLuceneIndex.getFieldNames()).thenAnswer(in -> fields.toArray(new String[fields.size()])); when(mockLuceneIndex.getLuceneSerializer()).thenAnswer(in -> luceneSerializerReference.get()); when(mockLuceneIndex.getName()).thenReturn(indexName); when(mockLuceneIndex.getRegionPath()).thenReturn(regionPath);
/** * @inheritDoc */ @Override @SuppressWarnings("all") public void destroy() throws Exception { LuceneIndex luceneIndex = getObject(); if (isLuceneIndexDestroyable(luceneIndex)) { resolveLuceneService().destroyIndex(luceneIndex.getName(), luceneIndex.getRegionPath()); } }
/** * @inheritDoc */ @Override @SuppressWarnings("all") public void destroy() throws Exception { LuceneIndex luceneIndex = getObject(); if (isLuceneIndexDestroyable(luceneIndex)) { resolveLuceneService().destroyIndex(luceneIndex.getName(), luceneIndex.getRegionPath()); } }