Search in sources :

Example 11 with Segment

use of com.cinchapi.concourse.server.storage.db.kernel.Segment in project concourse by cinchapi.

the class Database method getCorpusRecord.

/**
 * Return the CorpusRecord identified by {@code key}.
 *
 * @param key
 * @param query
 * @param toks {@code query} split by whitespace
 * @return the CorpusRecord
 */
private CorpusRecord getCorpusRecord(Text key, Text infix) {
    masterLock.readLock().lock();
    try {
        Composite composite = Composite.create(key, infix);
        Cache<Composite, CorpusRecord> cache = ENABLE_SEARCH_CACHE ? corpusCaches.computeIfAbsent(key, $ -> buildCache()) : DISABLED_CORPUS_CACHE;
        return cache.get(composite, () -> {
            CorpusRecord $ = CorpusRecord.createPartial(key, infix);
            for (Segment segment : segments) {
                segment.corpus().seek(composite, $);
            }
            return $;
        });
    } catch (ExecutionException e) {
        throw CheckedExceptions.wrapAsRuntimeException(e);
    } finally {
        masterLock.readLock().unlock();
    }
}
Also used : Composite(com.cinchapi.concourse.server.io.Composite) AnyStrings(com.cinchapi.common.base.AnyStrings) ListIterator(java.util.ListIterator) Logger(com.cinchapi.concourse.util.Logger) Receipt(com.cinchapi.concourse.server.storage.db.kernel.Segment.Receipt) Compactor(com.cinchapi.concourse.server.storage.db.compaction.Compactor) HashMultimap(com.google.common.collect.HashMultimap) Restricted(com.cinchapi.concourse.annotate.Restricted) TObjectSorter(com.cinchapi.concourse.server.model.TObjectSorter) TreeMultimap(com.google.common.collect.TreeMultimap) Transformers(com.cinchapi.concourse.util.Transformers) Map(java.util.Map) DurableStore(com.cinchapi.concourse.server.storage.DurableStore) Comparators(com.cinchapi.concourse.util.Comparators) ThreadFactory(java.util.concurrent.ThreadFactory) Path(java.nio.file.Path) AwaitableExecutorService(com.cinchapi.concourse.server.concurrent.AwaitableExecutorService) ThreadFactories(com.cinchapi.common.collect.concurrent.ThreadFactories) Buffer(com.cinchapi.concourse.server.storage.temp.Buffer) ImmutableMap(com.google.common.collect.ImmutableMap) FileSystem(com.cinchapi.concourse.server.io.FileSystem) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ManagedOperation(com.cinchapi.concourse.server.jmx.ManagedOperation) UUID(java.util.UUID) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) List(java.util.List) CorpusArtifact(com.cinchapi.concourse.server.storage.db.kernel.CorpusArtifact) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) CheckedExceptions(com.cinchapi.common.base.CheckedExceptions) CacheBuilder(com.google.common.cache.CacheBuilder) Text(com.cinchapi.concourse.server.model.Text) CacheStats(com.google.common.cache.CacheStats) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ArrayBuilder(com.cinchapi.common.base.ArrayBuilder) Verify(com.cinchapi.common.base.Verify) Callable(java.util.concurrent.Callable) NoOpScheduledExecutorService(com.cinchapi.concourse.server.concurrent.NoOpScheduledExecutorService) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Write(com.cinchapi.concourse.server.storage.temp.Write) Multimap(com.google.common.collect.Multimap) NoOpCompactor(com.cinchapi.concourse.server.storage.db.compaction.NoOpCompactor) NoOpCache(com.cinchapi.concourse.server.storage.cache.NoOpCache) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Aliases(com.cinchapi.concourse.thrift.TObject.Aliases) TStrings(com.cinchapi.concourse.util.TStrings) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) TObject(com.cinchapi.concourse.thrift.TObject) GlobalState(com.cinchapi.concourse.server.GlobalState) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SegmentLoadingException(com.cinchapi.concourse.server.storage.db.kernel.SegmentLoadingException) NoSuchElementException(java.util.NoSuchElementException) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Value(com.cinchapi.concourse.server.model.Value) LinkedHashSet(java.util.LinkedHashSet) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) Functions(com.google.common.base.Functions) Iterator(java.util.Iterator) HashCode(com.google.common.hash.HashCode) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) File(java.io.File) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Lock(java.util.concurrent.locks.Lock) Identifier(com.cinchapi.concourse.server.model.Identifier) Memory(com.cinchapi.concourse.server.storage.Memory) Paths(java.nio.file.Paths) Position(com.cinchapi.concourse.server.model.Position) Preconditions(com.google.common.base.Preconditions) WriteStreamProfiler(com.cinchapi.concourse.server.storage.WriteStreamProfiler) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) SimilarityCompactor(com.cinchapi.concourse.server.storage.db.compaction.similarity.SimilarityCompactor) Composite(com.cinchapi.concourse.server.io.Composite) ExecutionException(java.util.concurrent.ExecutionException) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment)

Example 12 with Segment

use of com.cinchapi.concourse.server.storage.db.kernel.Segment in project concourse by cinchapi.

the class SimilarityCompactor method compact.

@Override
protected List<Segment> compact(Segment... segments) {
    if (segments.length == 2) {
        Segment a = segments[0];
        Segment b = segments[1];
        long requiredDiskSpace = a.length() + b.length();
        if (storage().availableDiskSpace() > requiredDiskSpace && a.similarityWith(b) > minimumSimilarityThreshold) {
            // TODO:
            Segment merged = Segment.create((int) (a.count() + b.count()));
            // create
            // offheap
            Streams.concat(a.writes(), b.writes()).parallel().forEach(write -> merged.acquire(write));
            return ImmutableList.of(merged);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment)

Example 13 with Segment

use of com.cinchapi.concourse.server.storage.db.kernel.Segment in project concourse by cinchapi.

the class Upgrade0_11_0_1 method rollback.

@Override
protected void rollback() {
    logErrorMessage("Deleting Segment files");
    Environments.iterator(GlobalState.BUFFER_DIRECTORY, GlobalState.DATABASE_DIRECTORY).forEachRemaining(environment -> {
        Path directory = Paths.get(GlobalState.DATABASE_DIRECTORY).resolve(environment).resolve("segments");
        if (directory.toFile().exists()) {
            Iterable<Segment> segments = StorageFormatV3.load(directory);
            for (Segment segment : segments) {
                segment.delete();
            }
        }
    });
}
Also used : Path(java.nio.file.Path) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment)

Example 14 with Segment

use of com.cinchapi.concourse.server.storage.db.kernel.Segment in project concourse by cinchapi.

the class StorageFormatV3 method load.

/**
 * Load the {@link Segment Segments} from {@code directory}
 *
 * @param directory
 * @return an {@link Iterable} containing all the loaded {@link Segment
 *         Segments}
 */
public static Iterable<Segment> load(Path directory) {
    /*
         * NOTE: This implementation is copied from Database#start with a few
         * changes:
         * 1) Segments are loaded seriously instead of asynchronously
         * 2) Overlapping Segments are not removed
         */
    List<Segment> segments = Lists.newArrayList();
    Stream<Path> files = FileSystem.ls(directory);
    files.forEach(file -> {
        try {
            Segment segment = Segment.load(file);
            segments.add(segment);
        } catch (SegmentLoadingException e) {
            Logger.error("Error when trying to load Segment {}", file);
            Logger.error("", e);
        }
    });
    files.close();
    // Sort the segments in chronological order
    Collections.sort(segments, Segment.TEMPORAL_COMPARATOR);
    return segments;
}
Also used : Path(java.nio.file.Path) SegmentLoadingException(com.cinchapi.concourse.server.storage.db.kernel.SegmentLoadingException) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment)

Example 15 with Segment

use of com.cinchapi.concourse.server.storage.db.kernel.Segment in project concourse by cinchapi.

the class SimilarityCompactorTest method testSanityCheck.

@Test
public void testSanityCheck() {
    SegmentStorageSystem storage = CompactorTests.getStorageSystem();
    Segment a = Segment.create();
    a.acquire(Write.add("name", Convert.javaToThrift("jeff"), 1));
    a.acquire(Write.add("name", Convert.javaToThrift("ashleah"), 2));
    a.acquire(Write.add("age", Convert.javaToThrift(33), 2));
    a.acquire(Write.add("company", Convert.javaToThrift("Cinchapi"), 1));
    a.transfer(Paths.get(TestData.getTemporaryTestFile()));
    Segment b = Segment.create();
    b.acquire(Write.add("name", Convert.javaToThrift("Jeff"), 1));
    b.acquire(Write.remove("name", Convert.javaToThrift("jeff"), 1));
    b.acquire(Write.remove("name", Convert.javaToThrift("ashleah"), 2));
    b.acquire(Write.add("name", Convert.javaToThrift("Jeffery"), 1));
    b.acquire(Write.add("company", Convert.javaToThrift("Know Full Well"), 2));
    b.acquire(Write.add("age", Convert.javaToThrift(33), 1));
    b.acquire(Write.add("age", Convert.javaToThrift(33.0), 1));
    b.transfer(Paths.get(TestData.getTemporaryTestFile()));
    storage.segments().add(a);
    storage.segments().add(b);
    // seg0
    storage.segments().add(Segment.create());
    SimilarityCompactor compactor = new SimilarityCompactor(storage);
    compactor.minimumSimilarityThreshold(0);
    List<Write> expected = storage.segments().stream().flatMap(segment -> segment.writes()).collect(Collectors.toList());
    compactor.executeFullCompaction();
    List<Write> actual = storage.segments().stream().flatMap(segment -> segment.writes()).collect(Collectors.toList());
    Assert.assertEquals(2, storage.segments().size());
    Assert.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && // assert that no data
    actual.containsAll(expected));
    // lost...
    actual.forEach(System.out::println);
    for (int i = 0; i < actual.size(); ++i) {
        if (i > 0) {
            Identifier previous = actual.get(i - 1).getRecord();
            Identifier current = actual.get(i).getRecord();
            // Assert that, from table view, all records are grouped
            // together
            Assert.assertTrue(current.longValue() == previous.longValue() || current.longValue() == previous.longValue() + 1);
        }
    }
    Assert.assertEquals(ImmutableList.of(a, b), compactor.garbage());
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) CompactorTests(com.cinchapi.concourse.server.storage.db.compaction.CompactorTests) TestData(com.cinchapi.concourse.util.TestData) Test(org.junit.Test) SegmentStorageSystem(com.cinchapi.concourse.server.storage.db.SegmentStorageSystem) Write(com.cinchapi.concourse.server.storage.temp.Write) Collectors(java.util.stream.Collectors) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment) List(java.util.List) Identifier(com.cinchapi.concourse.server.model.Identifier) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) Convert(com.cinchapi.concourse.util.Convert) Assert(org.junit.Assert) Identifier(com.cinchapi.concourse.server.model.Identifier) SegmentStorageSystem(com.cinchapi.concourse.server.storage.db.SegmentStorageSystem) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment) Test(org.junit.Test)

Aggregations

Segment (com.cinchapi.concourse.server.storage.db.kernel.Segment)16 Path (java.nio.file.Path)5 Composite (com.cinchapi.concourse.server.io.Composite)3 Identifier (com.cinchapi.concourse.server.model.Identifier)3 SegmentLoadingException (com.cinchapi.concourse.server.storage.db.kernel.SegmentLoadingException)3 List (java.util.List)3 Test (org.junit.Test)3 AwaitableExecutorService (com.cinchapi.concourse.server.concurrent.AwaitableExecutorService)2 Text (com.cinchapi.concourse.server.model.Text)2 Value (com.cinchapi.concourse.server.model.Value)2 StoreTest (com.cinchapi.concourse.server.storage.StoreTest)2 WriteStreamProfiler (com.cinchapi.concourse.server.storage.WriteStreamProfiler)2 SegmentStorageSystem (com.cinchapi.concourse.server.storage.db.SegmentStorageSystem)2 SimilarityCompactor (com.cinchapi.concourse.server.storage.db.compaction.similarity.SimilarityCompactor)2 Write (com.cinchapi.concourse.server.storage.temp.Write)2 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 Paths (java.nio.file.Paths)2 Collectors (java.util.stream.Collectors)2 AnyStrings (com.cinchapi.common.base.AnyStrings)1