use of org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl in project geode by apache.
the class RawIndexRepositoryFactory method computeIndexRepository.
@Override
public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository) throws IOException {
final IndexRepository repo;
if (oldRepository != null) {
oldRepository.cleanup();
}
LuceneRawIndex indexForRaw = (LuceneRawIndex) index;
BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
Directory dir = null;
if (indexForRaw.withPersistence()) {
String bucketLocation = LuceneServiceImpl.getUniqueIndexName(index.getName(), index.getRegionPath() + "_" + bucketId);
File location = new File(index.getName(), bucketLocation);
if (!location.exists()) {
location.mkdirs();
}
dir = new NIOFSDirectory(location.toPath());
} else {
dir = new RAMDirectory();
}
IndexWriterConfig config = new IndexWriterConfig(indexForRaw.getAnalyzer());
IndexWriter writer = new IndexWriter(dir, config);
return new IndexRepositoryImpl(null, writer, serializer, indexForRaw.getIndexStats(), dataBucket, null, "");
}
use of org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl in project geode by apache.
the class DistributedScoringJUnitTest method uniformDistributionProducesComparableScores.
/**
* The goal of this test is to verify fair scoring if entries are uniformly distributed. It
* compares ordered results from a single IndexRepository (IR) with merged-ordered results from
* multiple repositories (ir1, ir2, ir3). The records inserted in IR are same as the combined
* records in irX. This simulates merging of results from buckets of a region.
*/
@Test
public void uniformDistributionProducesComparableScores() throws Exception {
// the strings below have been grouped to be split between three index repositories
String[] testStrings = { "hello world", "foo bar", "just any string", "hello world is usually the first program", "water on mars", "test world", "hello", "test hello test", "find the aliens" };
QueryParser parser = new QueryParser("txt", analyzer);
Query query = parser.parse("hello world");
IndexRepositoryImpl singleIndexRepo = createIndexRepo();
populateIndex(testStrings, singleIndexRepo, 0, testStrings.length);
TopEntriesCollector collector = new TopEntriesCollector();
singleIndexRepo.query(query, 100, collector);
List<EntryScore<String>> singleResult = collector.getEntries().getHits();
IndexRepositoryImpl distIR1 = createIndexRepo();
populateIndex(testStrings, distIR1, 0, testStrings.length / 3);
IndexRepositoryImpl distIR2 = createIndexRepo();
populateIndex(testStrings, distIR2, testStrings.length / 3, (testStrings.length * 2) / 3);
IndexRepositoryImpl distIR3 = createIndexRepo();
populateIndex(testStrings, distIR3, (testStrings.length * 2) / 3, testStrings.length);
ArrayList<TopEntriesCollector> collectors = new ArrayList<>();
TopEntriesCollectorManager manager = new TopEntriesCollectorManager();
TopEntriesCollector collector1 = manager.newCollector("");
distIR1.query(query, 100, collector1);
collectors.add(collector1);
TopEntriesCollector collector2 = manager.newCollector("");
distIR2.query(query, 100, collector2);
collectors.add(collector2);
TopEntriesCollector collector3 = manager.newCollector("");
distIR3.query(query, 100, collector3);
collectors.add(collector3);
List<EntryScore<String>> distResult = manager.reduce(collectors).getEntries().getHits();
Assert.assertEquals(singleResult.size(), distResult.size());
Assert.assertTrue(singleResult.size() > 0);
for (Iterator single = distResult.iterator(), dist = singleResult.iterator(); single.hasNext() && dist.hasNext(); ) {
EntryScore<String> singleScore = (EntryScore<String>) single.next();
EntryScore<String> distScore = (EntryScore<String>) dist.next();
Assert.assertEquals(singleScore.getKey(), distScore.getKey());
}
}
use of org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl in project geode by apache.
the class IndexRepositoryFactory method computeIndexRepository.
public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion, final IndexRepository oldRepository) throws IOException {
LuceneIndexForPartitionedRegion indexForPR = (LuceneIndexForPartitionedRegion) index;
final PartitionedRegion fileRegion = indexForPR.getFileAndChunkRegion();
BucketRegion fileAndChunkBucket = getMatchingBucket(fileRegion, bucketId);
BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
boolean success = false;
if (fileAndChunkBucket == null) {
if (oldRepository != null) {
oldRepository.cleanup();
}
return null;
}
if (!fileAndChunkBucket.getBucketAdvisor().isPrimary()) {
if (oldRepository != null) {
oldRepository.cleanup();
}
return null;
}
if (oldRepository != null && !oldRepository.isClosed()) {
return oldRepository;
}
if (oldRepository != null) {
oldRepository.cleanup();
}
DistributedLockService lockService = getLockService();
String lockName = getLockName(fileAndChunkBucket);
while (!lockService.lock(lockName, 100, -1)) {
if (!fileAndChunkBucket.getBucketAdvisor().isPrimary()) {
return null;
}
}
final IndexRepository repo;
try {
RegionDirectory dir = new RegionDirectory(getBucketTargetingMap(fileAndChunkBucket, bucketId), indexForPR.getFileSystemStats());
IndexWriterConfig config = new IndexWriterConfig(indexForPR.getAnalyzer());
IndexWriter writer = new IndexWriter(dir, config);
repo = new IndexRepositoryImpl(fileAndChunkBucket, writer, serializer, indexForPR.getIndexStats(), dataBucket, lockService, lockName);
success = true;
return repo;
} catch (IOException e) {
logger.info("Exception thrown while constructing Lucene Index for bucket:" + bucketId + " for file region:" + fileAndChunkBucket.getFullPath());
throw e;
} finally {
if (!success) {
lockService.unlock(lockName);
}
}
}
use of org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl in project geode by apache.
the class DistributedScoringJUnitTest method createIndexRepo.
private IndexRepositoryImpl createIndexRepo() throws IOException {
ConcurrentHashMap fileAndChunkRegion = new ConcurrentHashMap();
RegionDirectory dir = new RegionDirectory(fileAndChunkRegion, fileSystemStats);
IndexWriterConfig config = new IndexWriterConfig(analyzer);
IndexWriter writer = new IndexWriter(dir, config);
return new IndexRepositoryImpl(region, writer, mapper, indexStats, null, null, "");
}
use of org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl in project geode by apache.
the class PartitionedRepositoryManagerJUnitTest method getByRegion.
@Test
public void getByRegion() throws BucketNotFoundException {
setUpMockBucket(0);
setUpMockBucket(1);
Set<Integer> buckets = new LinkedHashSet<Integer>(Arrays.asList(0, 1));
InternalRegionFunctionContext ctx = Mockito.mock(InternalRegionFunctionContext.class);
when(ctx.getLocalBucketSet((any()))).thenReturn(buckets);
Collection<IndexRepository> repos = repoManager.getRepositories(ctx);
assertEquals(2, repos.size());
Iterator<IndexRepository> itr = repos.iterator();
IndexRepositoryImpl repo0 = (IndexRepositoryImpl) itr.next();
IndexRepositoryImpl repo1 = (IndexRepositoryImpl) itr.next();
assertNotNull(repo0);
assertNotNull(repo1);
assertNotEquals(repo0, repo1);
checkRepository(repo0, 0);
checkRepository(repo1, 1);
}
Aggregations