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();
}
});
}
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();
}
}
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();
}
}
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);
}
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);
}
Aggregations