Search in sources :

Example 26 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Upgrade0_11_0_1 method doTask.

@Override
protected void doTask() {
    Environments.iterator(GlobalState.BUFFER_DIRECTORY, GlobalState.DATABASE_DIRECTORY).forEachRemaining(environment -> {
        logInfoMessage("Upgrading Storage Format v2 data files to Storage Format v3 in environment {}", environment);
        Path directory = Paths.get(GlobalState.DATABASE_DIRECTORY).resolve(environment);
        Database db = new Database(directory);
        db.start();
        try {
            Path cpb = directory.resolve("cpb");
            Iterable<Block<Identifier, Text, Value>> blocks = StorageFormatV2.load(cpb, TableRevision.class);
            for (Block<Identifier, Text, Value> block : blocks) {
                for (Revision<Identifier, Text, Value> revision : block) {
                    Write write = Reflection.newInstance(Write.class, revision.getType(), revision.getKey(), revision.getValue(), revision.getLocator(), // (authorized)
                    revision.getVersion());
                    db.accept(write);
                }
                db.sync();
                logInfoMessage("Finished transferring v2 data Block {} to v3 Segment format", block.getId());
            }
        } finally {
            db.stop();
        }
    });
}
Also used : Path(java.nio.file.Path) Write(com.cinchapi.concourse.server.storage.temp.Write) Identifier(com.cinchapi.concourse.server.model.Identifier) Database(com.cinchapi.concourse.server.storage.db.Database) Value(com.cinchapi.concourse.server.model.Value) Block(com.cinchapi.concourse.server.storage.format.StorageFormatV2.Block) Text(com.cinchapi.concourse.server.model.Text)

Example 27 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class IndexRecord method gather.

/**
 * Return all the keys that mapped to the {@code record} at
 * {@code timestamp}.
 * <p>
 * In the broader {@link Database} sense, this method can be used to return
 * all the data "values" that were stored within a data "record" under a
 * data "key" that is equivalent to this {@link IndexRecord
 * SecondaryRecord's} locator at {@code timestamp} (similar to
 * {@link Database#select(long, long)}).
 * </p>
 * <p>
 * NOTE: The order of the items in the returned {@link Set} are not
 * necessarily reflective of the order in which they were inserted into the
 * {@link IndexRecord}.
 * </p>
 *
 * @param record
 * @return a {@link Set} containing all the keys that map to the
 *         {@code value}
 */
public Set<Value> gather(Identifier record, long timestamp) {
    Preconditions.checkState(!isPartial(), "Cannot gather from a partial Secondary Record.");
    read.lock();
    try {
        Map<Identifier, Set<Value>> slice = cube.slice(timestamp);
        if (slice == null) {
            Set<Value> values = Sets.newHashSet();
            Set<Entry<Value, Set<Identifier>>> entries = timestamp != Time.NONE ? LazyTransformSet.of(history.entrySet(), entry -> new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), extractHistoricalValues(entry.getValue(), timestamp))) : present.entrySet();
            for (Entry<Value, Set<Identifier>> entry : entries) {
                Value value = entry.getKey();
                Set<Identifier> records = entry.getValue();
                if (records.contains(record)) {
                    values.add(value);
                }
                for (Identifier $record : records) {
                    if ($record.equals(record)) {
                        values.add(value);
                    }
                    cube.put($record, value, timestamp);
                }
            }
            return values;
        } else {
            return slice.getOrDefault(record, ImmutableSet.of());
        }
    } finally {
        read.unlock();
    }
}
Also used : PackagePrivate(com.cinchapi.concourse.annotate.PackagePrivate) BiPredicate(java.util.function.BiPredicate) Matcher(java.util.regex.Matcher) MultimapViews(com.cinchapi.concourse.util.MultimapViews) CoalescableTreeMap(com.cinchapi.common.collect.CoalescableTreeMap) Map(java.util.Map) Action(com.cinchapi.concourse.server.storage.Action) SoftReference(java.lang.ref.SoftReference) Value(com.cinchapi.concourse.server.model.Value) Nullable(javax.annotation.Nullable) DoNotInvoke(com.cinchapi.concourse.annotate.DoNotInvoke) Time(com.cinchapi.concourse.time.Time) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) NavigableSet(java.util.NavigableSet) ThreadSafe(javax.annotation.concurrent.ThreadSafe) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) AbstractMap(java.util.AbstractMap) List(java.util.List) Operator(com.cinchapi.concourse.thrift.Operator) Identifier(com.cinchapi.concourse.server.model.Identifier) Versioned(com.cinchapi.concourse.server.storage.Versioned) Entry(java.util.Map.Entry) Preconditions(com.google.common.base.Preconditions) Pattern(java.util.regex.Pattern) LazyTransformSet(com.cinchapi.common.collect.lazy.LazyTransformSet) Text(com.cinchapi.concourse.server.model.Text) Entry(java.util.Map.Entry) Identifier(com.cinchapi.concourse.server.model.Identifier) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) LazyTransformSet(com.cinchapi.common.collect.lazy.LazyTransformSet) Value(com.cinchapi.concourse.server.model.Value)

Example 28 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class IndexRecord method coalesce.

/**
 * Return all the key/value mappings of keys that matched {@code key} at
 * {@code timestamp} in a case insensitive manner.
 *
 * @param key
 * @param timestamp
 * @return the matching entries
 */
private Map<Value, Set<Identifier>> coalesce(Value key, long timestamp) {
    read.lock();
    try {
        Map<Value, Set<Identifier>> data = Maps.newLinkedHashMap();
        Map<Value, List<CompactRevision<Identifier>>> coalesced = ((CoalescableTreeMap<Value, List<CompactRevision<Identifier>>>) history).coalesce(key, CASE_INSENSITIVE_COALESCER);
        for (Entry<Value, List<CompactRevision<Identifier>>> entry : coalesced.entrySet()) {
            Value stored = entry.getKey();
            List<CompactRevision<Identifier>> revisions = entry.getValue();
            Set<Identifier> values = Sets.newLinkedHashSet();
            Iterator<CompactRevision<Identifier>> it = revisions.iterator();
            while (it.hasNext()) {
                CompactRevision<Identifier> revision = it.next();
                if (revision.getVersion() <= timestamp) {
                    if (revision.getType() == Action.ADD) {
                        values.add(revision.getValue());
                    } else {
                        values.remove(revision.getValue());
                    }
                } else {
                    break;
                }
            }
            data.put(stored, values);
        }
        return data;
    } finally {
        read.unlock();
    }
}
Also used : CoalescableTreeMap(com.cinchapi.common.collect.CoalescableTreeMap) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) LazyTransformSet(com.cinchapi.common.collect.lazy.LazyTransformSet) Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) List(java.util.List)

Example 29 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method select.

@Override
public Set<TObject> select(String key, long record) {
    Identifier L = Identifier.of(record);
    Text K = Text.wrapCached(key);
    TableRecord table = getTableRecord(L, K);
    Set<Value> data = table.get(K);
    return Transformers.transformSet(data, Value::getTObject);
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Example 30 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class ByteableCollectionsTest method testStreamIterator.

@Test
public void testStreamIterator() {
    Path file = Paths.get(TestData.getTemporaryTestFile());
    List<Identifier> values = Lists.newArrayList();
    int count = 10;
    for (int i = 0; i < count; ++i) {
        values.add(Identifier.of(i));
    }
    ByteBuffer bytes = ByteableCollections.toByteBuffer(values);
    FileSystem.writeBytes(bytes, file.toString());
    int bufferSize = 64;
    Iterator<ByteBuffer> it = ByteableCollections.stream(file, bufferSize);
    List<Identifier> newValues = Lists.newArrayList();
    while (it.hasNext()) {
        newValues.add(Identifier.fromByteBuffer(it.next()));
    }
    Assert.assertEquals(values, newValues);
}
Also used : Path(java.nio.file.Path) Identifier(com.cinchapi.concourse.server.model.Identifier) ByteBuffer(java.nio.ByteBuffer) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Aggregations

Identifier (com.cinchapi.concourse.server.model.Identifier)40 Text (com.cinchapi.concourse.server.model.Text)28 Value (com.cinchapi.concourse.server.model.Value)25 Test (org.junit.Test)18 Set (java.util.Set)13 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)9 LinkedHashSet (java.util.LinkedHashSet)7 ByteBuffer (java.nio.ByteBuffer)6 Path (java.nio.file.Path)6 Write (com.cinchapi.concourse.server.storage.temp.Write)4 List (java.util.List)4 LazyTransformSet (com.cinchapi.common.collect.lazy.LazyTransformSet)3 Position (com.cinchapi.concourse.server.model.Position)3 Action (com.cinchapi.concourse.server.storage.Action)3 Range (com.cinchapi.concourse.server.storage.db.kernel.Manifest.Range)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 NavigableSet (java.util.NavigableSet)3 CoalescableTreeMap (com.cinchapi.common.collect.CoalescableTreeMap)2 Composite (com.cinchapi.concourse.server.io.Composite)2 CorpusRecord (com.cinchapi.concourse.server.storage.db.CorpusRecord)2