use of com.sap.hadoop.ds.streams.Streams.ByteArrayOS in project SQLWindowing by hbutani.
the class PartitionedByteBasedSortedMap method getValue.
public int getValue(Writable key, Writable value) throws BaseException {
LockUtils.lock(lock.readLock());
try {
DataOStream dos = Streams.dos.get();
ByteArrayOS bos = dos.getUnderlyingStream();
bos.reset();
key.write(dos);
int p = splitList.getPartition(bos.bytearray(), 0, bos.len());
ByteBasedSortedMap mp = partitions.get(p);
return mp.getValue(key, value);
} catch (IOException ie) {
throw new BaseException(ie);
} finally {
lock.readLock().unlock();
}
}
use of com.sap.hadoop.ds.streams.Streams.ByteArrayOS in project SQLWindowing by hbutani.
the class PartitionedByteBasedSortedMap method put.
public void put(Writable key, Writable value) throws BaseException {
LockUtils.lock(lock.writeLock());
try {
DataOStream dos = Streams.dos.get();
ByteArrayOS bos = dos.getUnderlyingStream();
bos.reset();
key.write(dos);
int p = splitList.getPartition(bos.bytearray(), 0, bos.len());
ByteBasedSortedMap mp = bringInMemory(p);
try {
int prevSz = mp.size();
mp.put(key, value);
if (mp.size() > prevSz)
currentSize++;
fixStartPositions = true;
persistRandom();
} catch (MapFullException oe) {
ByteBasedSortedMap[] parts = mp.split();
// System.out.println(parts[0]);
// System.out.println(parts[1]);
partitions.set(p, parts[1]);
partitions.add(p, parts[0]);
byte[] b = parts[0].getLastKey();
splitList.splitPartition(p, b, 0, b.length);
put(key, value);
}
} catch (IOException ie) {
throw new BaseException(ie);
} finally {
lock.writeLock().unlock();
}
}
Aggregations