use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.
the class FSWindowDataManager method retrieve.
private Object retrieve(FSWindowReplayWAL wal, long windowId) throws IOException {
if (windowId > largestCompletedWindow || wal.walEndPointerAfterRecovery == null) {
return null;
}
FileSystemWAL.FileSystemWALReader reader = wal.getReader();
while (reader.getCurrentPointer() == null || reader.getCurrentPointer().compareTo(wal.walEndPointerAfterRecovery) < 0) {
long currentWindow;
if (wal.retrievedWindow == null) {
wal.retrievedWindow = readNext(reader);
Preconditions.checkNotNull(wal.retrievedWindow);
}
currentWindow = Longs.fromByteArray(wal.retrievedWindow.toByteArray());
if (windowId == currentWindow) {
Slice data = readNext(reader);
Preconditions.checkNotNull(data, "data is null");
wal.windowWalParts.put(currentWindow, reader.getCurrentPointer().getPartNum());
// null or next window
wal.retrievedWindow = readNext(reader);
return fromSlice(data);
} else if (windowId < currentWindow) {
// no artifact saved corresponding to that window and artifact is not read.
return null;
} else {
// windowId > current window so we skip the data
skipNext(reader);
wal.windowWalParts.put(currentWindow, reader.getCurrentPointer().getPartNum());
// null or next window
wal.retrievedWindow = readNext(reader);
if (wal.retrievedWindow == null) {
// nothing else to read
return null;
}
}
}
return null;
}
use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.
the class AbstractManagedStateImpl method getValueFromBucketAsync.
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
protected Future<Slice> getValueFromBucketAsync(long bucketId, long timeBucket, @NotNull Slice key) {
Preconditions.checkNotNull(key, "key");
long bucketIdx = prepareBucket(bucketId);
Bucket bucket = buckets.get(bucketIdx);
synchronized (bucket) {
Slice cachedVal = bucket.get(key, timeBucket, Bucket.ReadSource.MEMORY);
if (cachedVal != null) {
return Futures.immediateFuture(cachedVal);
}
ValueFetchTask valueFetchTask = new ValueFetchTask(bucket, key, timeBucket, this);
tasksPerBucketId.put(bucket.getBucketId(), valueFetchTask);
return readerService.submit(valueFetchTask);
}
}
use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.
the class IncrementalCheckpointManager method retrieveAllWindows.
/**
* Retrieves artifacts available for all the windows saved by the enclosing partitions.
* @return artifact saved per window.
* @throws IOException
*/
public Map<Long, Object> retrieveAllWindows() throws IOException {
Map<Long, Object> artifactPerWindow = new HashMap<>();
FileSystemWAL.FileSystemWALReader reader = getWal().getReader();
reader.seek(getWal().getWalStartPointer());
Slice windowSlice = readNext(reader);
while (reader.getCurrentPointer().compareTo(getWal().getWalEndPointerAfterRecovery()) < 0 && windowSlice != null) {
long window = Longs.fromByteArray(windowSlice.toByteArray());
Object data = fromSlice(readNext(reader));
artifactPerWindow.put(window, data);
// null or next window
windowSlice = readNext(reader);
}
reader.seek(getWal().getWalStartPointer());
return artifactPerWindow;
}
use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.
the class ManagedTimeStateMultiValue method put.
/**
* Inserts the (k,v) into the store.
* @param k key
* @param v value
* @return true if the given (k,v) is successfully inserted into the store otherwise false.
*/
@Override
public boolean put(@Nullable K k, @Nullable V v) {
if (isKeyContainsMultiValue) {
Slice keySlice = streamCodec.toByteArray(k);
long bucketId = getBucketId(k);
Slice valueSlice = store.getSync(bucketId, keySlice);
List<V> listOb;
if (valueSlice == null || valueSlice.length == 0) {
listOb = new ArrayList<>();
} else {
listOb = (List<V>) streamCodec.fromByteArray(valueSlice);
}
listOb.add(v);
return insertInStore(bucketId, timeBucket, keySlice, streamCodec.toByteArray(listOb));
}
return insertInStore(getBucketId(k), timeBucket, streamCodec.toByteArray(k), streamCodec.toByteArray(v));
}
use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.
the class ManagedTimeStateMultiValue method get.
/**
* Return the list of values from the store
* @param k given key
* @return list of values
*/
@Override
public List<V> get(@Nullable K k) {
List<V> value = null;
Slice valueSlice = store.getSync(getBucketId(k), streamCodec.toByteArray(k));
if (valueSlice == null || valueSlice.length == 0 || valueSlice.buffer == null) {
return null;
}
if (isKeyContainsMultiValue) {
return (List<V>) streamCodec.fromByteArray(valueSlice);
}
value = new ArrayList<>();
value.add((V) streamCodec.fromByteArray(valueSlice));
return value;
}
Aggregations