Search in sources :

Example 1 with Composite

use of com.cinchapi.concourse.server.io.Composite in project concourse by cinchapi.

the class Database method accept.

@Override
public void accept(Write write) {
    // is only called from the Buffer, which transports data serially.
    if (running) {
        try {
            Receipt receipt = seg0.acquire(write, writer);
            Logger.debug("Indexed '{}' in {}", write, seg0);
            // Update cached records
            TableRecord cpr = tableCache.getIfPresent(receipt.table().getLocatorComposite());
            TableRecord cppr = tablePartialCache.getIfPresent(receipt.table().getLocatorKeyComposite());
            IndexRecord csr = indexCache.getIfPresent(receipt.index().getLocatorComposite());
            if (cpr != null) {
                cpr.append(receipt.table().revision());
            }
            if (cppr != null) {
                cppr.append(receipt.table().revision());
            }
            if (csr != null) {
                csr.append(receipt.index().revision());
            }
            if (ENABLE_SEARCH_CACHE) {
                Cache<Composite, CorpusRecord> cache = corpusCaches.get(write.getKey());
                if (cache != null) {
                    for (CorpusArtifact artifact : receipt.corpus()) {
                        CorpusRecord corpus = cache.getIfPresent(artifact.getLocatorKeyComposite());
                        if (corpus != null) {
                            corpus.append(artifact.revision());
                        }
                    }
                }
            }
        } catch (InterruptedException e) {
            Logger.warn("The database was interrupted while trying to accept {}. " + "If the write could not be fully accepted, it will " + "remain in the buffer and re-tried when the Database is able to accept writes.", write);
            Thread.currentThread().interrupt();
            return;
        }
    } else {
        // The #accept method may be called when the database is stopped
        // during test cases
        Logger.warn("The database is being asked to accept a Write, even though it is not running.");
        seg0.acquire(write);
    }
}
Also used : Receipt(com.cinchapi.concourse.server.storage.db.kernel.Segment.Receipt) Composite(com.cinchapi.concourse.server.io.Composite) CorpusArtifact(com.cinchapi.concourse.server.storage.db.kernel.CorpusArtifact)

Example 2 with Composite

use of com.cinchapi.concourse.server.io.Composite in project concourse by cinchapi.

the class Database method getLookupRecord.

/**
 * Return a {@link Record} that is guaranteed to have the present state for
 * whether {@code value} is contained for {@code key} in {@code record}. The
 * truth of this query can be obtained using the
 * {@link Record#contains(com.cinchapi.concourse.server.io.Byteable, com.cinchapi.concourse.server.io.Byteable)}
 * method on the returned {@link Record}.
 * <p>
 * The query answered by this {@link Record} can also be answered by that
 * returned from {@link #getTableRecord(Identifier)}
 * and {@link #getTableRecord(Identifier, Text)}, but this method will
 * attempt to short circuit by not loading {@link Revisions} that don't
 * involve {@code record}, {@code key} and {@code value}. As a result, the
 * returned {@link Record} is not cached and cannot be reliably used for
 * other queries.
 * </p>
 *
 * @param record
 * @param key
 * @param value
 * @return the {@link Record}
 */
private Record<Identifier, Text, Value> getLookupRecord(Identifier record, Text key, Value value) {
    masterLock.readLock().lock();
    try {
        // First, see if there is a cached full or partial Record that can
        // allow a lookup to be performed.
        Composite c1 = Composite.create(record);
        Composite c2 = null;
        Composite c3 = null;
        Record<Identifier, Text, Value> lookup = tableCache.getIfPresent(c1);
        if (lookup == null) {
            c2 = Composite.create(record, key);
            lookup = tablePartialCache.getIfPresent(c2);
        }
        if (lookup == null) {
            // Create a LookupRecord to handle this, but DO NOT cache it
            // since it has no other utility.
            c3 = Composite.create(record, key, value);
            lookup = new LookupRecord(record, key, value);
            for (Segment segment : segments) {
                if (segment.table().mightContain(c3)) {
                    // Whenever it is possible that the LKV exists, we must
                    // gather Revisions for LK within a Record so the
                    // current state of LKV can be determined.
                    segment.table().seek(c2, lookup);
                }
            }
        }
        return lookup;
    } finally {
        masterLock.readLock().unlock();
    }
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Composite(com.cinchapi.concourse.server.io.Composite) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment)

Example 3 with Composite

use of com.cinchapi.concourse.server.io.Composite in project concourse by cinchapi.

the class Database method getTableRecord.

/**
 * Return the potentially partial TableRecord identified by {@code key} in
 * {@code identifier}.
 * <p>
 * While the returned {@link TableRecord} may not be
 * {@link TableRecord#isPartial() partial}, the caller should interact
 * with it as if it is (e.g. do not perform reads for any other keys besides
 * {@code key}.
 * </p>
 *
 * @param identifier
 * @param key
 * @return the TableRecord
 */
private TableRecord getTableRecord(Identifier identifier, Text key) {
    masterLock.readLock().lock();
    try {
        // Before loading a partial record, see if the full record is
        // present in memory.
        TableRecord table = tableCache.getIfPresent(Composite.create(identifier));
        if (table == null) {
            Composite composite = Composite.create(identifier, key);
            table = tablePartialCache.get(composite, () -> {
                TableRecord $ = TableRecord.createPartial(identifier, key);
                for (Segment segment : segments) {
                    segment.table().seek(composite, $);
                }
                return $;
            });
        }
        return table;
    } catch (ExecutionException e) {
        throw CheckedExceptions.wrapAsRuntimeException(e);
    } finally {
        masterLock.readLock().unlock();
    }
}
Also used : Composite(com.cinchapi.concourse.server.io.Composite) ExecutionException(java.util.concurrent.ExecutionException) Segment(com.cinchapi.concourse.server.storage.db.kernel.Segment)

Example 4 with Composite

use of com.cinchapi.concourse.server.io.Composite in project concourse by cinchapi.

the class ManifestTest method testBackgroundLoadEntriesWorksMiss.

@SuppressWarnings("rawtypes")
@Test
public void testBackgroundLoadEntriesWorksMiss() {
    Set<Composite> composites = Sets.newLinkedHashSet();
    Manifest manifest = Manifest.create(100000);
    for (int i = 0; i < TestData.getScaleCount(); ++i) {
        Composite composite = Composite.create(TestData.getText());
        if (composites.add(composite)) {
            manifest.putStart(i, composite);
            manifest.putEnd(i + 1, composite);
        }
    }
    Path file = Paths.get(TestData.getTemporaryTestFile());
    manifest.transfer(file);
    manifest = Manifest.load(file, 0, FileSystem.getFileSize(file.toString()));
    Composite composite = null;
    while (composite == null || composites.contains(composite)) {
        composite = Composite.create(TestData.getText());
    }
    Map map = Reflection.call(manifest, "entries", composite);
    Assert.assertFalse(map.containsKey(composite));
    Assert.assertTrue(map.isEmpty());
    while (Reflection.get("$entries", manifest) == null || Reflection.call(Reflection.get("$entries", manifest), "get") == null) {
    /* spin */
    }
    map = Reflection.call(manifest, "entries", composite);
    Assert.assertFalse(map.containsKey(composite));
    Assert.assertEquals(composites.size(), map.size());
    map = Reflection.call(manifest, "entries");
    Assert.assertFalse(map.containsKey(composite));
    Assert.assertEquals(composites.size(), map.size());
}
Also used : Path(java.nio.file.Path) Composite(com.cinchapi.concourse.server.io.Composite) Map(java.util.Map) Test(org.junit.Test) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest)

Example 5 with Composite

use of com.cinchapi.concourse.server.io.Composite in project concourse by cinchapi.

the class RecordTest method getAction.

/**
 * Get the appropriate action for {@code locator}, {@code key} and
 * {@code value} to maintain the offsetting constraint.
 *
 * @param locator
 * @param key
 * @param value
 * @return the appropriate action
 */
protected Action getAction(L locator, K key, V value) {
    Composite comp = Composite.create(locator, key, value);
    Action action = actions.get(comp);
    if (action == null || action == Action.REMOVE) {
        action = Action.ADD;
    } else {
        action = Action.REMOVE;
    }
    actions.put(comp, action);
    return action;
}
Also used : Action(com.cinchapi.concourse.server.storage.Action) Composite(com.cinchapi.concourse.server.io.Composite)

Aggregations

Composite (com.cinchapi.concourse.server.io.Composite)10 Path (java.nio.file.Path)4 Test (org.junit.Test)4 Identifier (com.cinchapi.concourse.server.model.Identifier)3 Text (com.cinchapi.concourse.server.model.Text)3 Segment (com.cinchapi.concourse.server.storage.db.kernel.Segment)3 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)3 Map (java.util.Map)3 Value (com.cinchapi.concourse.server.model.Value)2 CorpusArtifact (com.cinchapi.concourse.server.storage.db.kernel.CorpusArtifact)2 Receipt (com.cinchapi.concourse.server.storage.db.kernel.Segment.Receipt)2 AnyStrings (com.cinchapi.common.base.AnyStrings)1 ArrayBuilder (com.cinchapi.common.base.ArrayBuilder)1 CheckedExceptions (com.cinchapi.common.base.CheckedExceptions)1 Verify (com.cinchapi.common.base.Verify)1 ThreadFactories (com.cinchapi.common.collect.concurrent.ThreadFactories)1 Restricted (com.cinchapi.concourse.annotate.Restricted)1 GlobalState (com.cinchapi.concourse.server.GlobalState)1 AwaitableExecutorService (com.cinchapi.concourse.server.concurrent.AwaitableExecutorService)1 NoOpScheduledExecutorService (com.cinchapi.concourse.server.concurrent.NoOpScheduledExecutorService)1