Search in sources :

Example 1 with RegionDirectory

use of org.apache.geode.cache.lucene.internal.directory.RegionDirectory in project geode by apache.

the class IndexRepositoryImplJUnitTest method setUp.

@Before
public void setUp() throws IOException {
    ConcurrentHashMap fileAndChunkRegion = new ConcurrentHashMap();
    fileSystemStats = mock(FileSystemStats.class);
    RegionDirectory dir = new RegionDirectory(fileAndChunkRegion, fileSystemStats);
    IndexWriterConfig config = new IndexWriterConfig(analyzer);
    writer = new IndexWriter(dir, config);
    String[] indexedFields = new String[] { "s", "i", "l", "d", "f", "s2", "missing" };
    mapper = new HeterogeneousLuceneSerializer(indexedFields);
    region = Mockito.mock(Region.class);
    userRegion = Mockito.mock(BucketRegion.class);
    BucketAdvisor bucketAdvisor = Mockito.mock(BucketAdvisor.class);
    Mockito.when(bucketAdvisor.isPrimary()).thenReturn(true);
    Mockito.when(((BucketRegion) userRegion).getBucketAdvisor()).thenReturn(bucketAdvisor);
    Mockito.when(((BucketRegion) userRegion).getBucketAdvisor().isPrimary()).thenReturn(true);
    stats = Mockito.mock(LuceneIndexStats.class);
    Mockito.when(userRegion.isDestroyed()).thenReturn(false);
    repo = new IndexRepositoryImpl(region, writer, mapper, stats, userRegion, mock(DistributedLockService.class), "lockName");
}
Also used : LuceneIndexStats(org.apache.geode.cache.lucene.internal.LuceneIndexStats) HeterogeneousLuceneSerializer(org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer) FileSystemStats(org.apache.geode.cache.lucene.internal.filesystem.FileSystemStats) BucketRegion(org.apache.geode.internal.cache.BucketRegion) IndexWriter(org.apache.lucene.index.IndexWriter) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RegionDirectory(org.apache.geode.cache.lucene.internal.directory.RegionDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 2 with RegionDirectory

use of org.apache.geode.cache.lucene.internal.directory.RegionDirectory 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);
        }
    }
}
Also used : IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) BucketRegion(org.apache.geode.internal.cache.BucketRegion) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DistributedLockService(org.apache.geode.distributed.DistributedLockService) IOException(java.io.IOException) RegionDirectory(org.apache.geode.cache.lucene.internal.directory.RegionDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) IndexRepositoryImpl(org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl)

Example 3 with RegionDirectory

use of org.apache.geode.cache.lucene.internal.directory.RegionDirectory 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, "");
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RegionDirectory(org.apache.geode.cache.lucene.internal.directory.RegionDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) IndexRepositoryImpl(org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl)

Example 4 with RegionDirectory

use of org.apache.geode.cache.lucene.internal.directory.RegionDirectory in project geode by apache.

the class PartitionedRepositoryManagerJUnitTest method checkRepository.

protected void checkRepository(IndexRepositoryImpl repo0, int bucketId) {
    IndexWriter writer0 = repo0.getWriter();
    RegionDirectory dir0 = (RegionDirectory) writer0.getDirectory();
    assertEquals(new BucketTargetingMap(fileAndChunkBuckets.get(bucketId), bucketId), dir0.getFileSystem().getFileAndChunkRegion());
    assertEquals(serializer, repo0.getSerializer());
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) BucketTargetingMap(org.apache.geode.cache.lucene.internal.partition.BucketTargetingMap) RegionDirectory(org.apache.geode.cache.lucene.internal.directory.RegionDirectory)

Aggregations

RegionDirectory (org.apache.geode.cache.lucene.internal.directory.RegionDirectory)4 IndexWriter (org.apache.lucene.index.IndexWriter)4 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 IndexRepositoryImpl (org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl)2 BucketRegion (org.apache.geode.internal.cache.BucketRegion)2 IOException (java.io.IOException)1 Region (org.apache.geode.cache.Region)1 LuceneIndexStats (org.apache.geode.cache.lucene.internal.LuceneIndexStats)1 FileSystemStats (org.apache.geode.cache.lucene.internal.filesystem.FileSystemStats)1 BucketTargetingMap (org.apache.geode.cache.lucene.internal.partition.BucketTargetingMap)1 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)1 HeterogeneousLuceneSerializer (org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer)1 DistributedLockService (org.apache.geode.distributed.DistributedLockService)1 BucketAdvisor (org.apache.geode.internal.cache.BucketAdvisor)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 Before (org.junit.Before)1