Search in sources :

Example 1 with DataArray

use of krati.array.DataArray in project voldemort by voldemort.

the class KratiStorageEngine method entries.

@Override
public ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> entries() {
    List<Pair<ByteArray, Versioned<byte[]>>> returnedList = new ArrayList<Pair<ByteArray, Versioned<byte[]>>>();
    DataArray array = datastore.getDataArray();
    for (int index = 0; index < array.length(); index++) {
        byte[] returnedBytes = array.get(index);
        if (returnedBytes != null) {
            // Extract the key value pair from this
            // TODO: Move to DynamicDataStore code
            ByteBuffer bb = ByteBuffer.wrap(returnedBytes);
            int cnt = bb.getInt();
            // Loop over all keys at this index
            for (int i = 0; i < cnt; i++) {
                int keyLen = bb.getInt();
                byte[] key = new byte[keyLen];
                bb.get(key);
                int valueLen = bb.getInt();
                byte[] value = new byte[valueLen];
                bb.get(value);
                List<Versioned<byte[]>> versions;
                try {
                    versions = disassembleValues(value);
                } catch (IOException e) {
                    versions = null;
                }
                if (versions != null) {
                    Iterator<Versioned<byte[]>> iterVersions = versions.iterator();
                    while (iterVersions.hasNext()) {
                        Versioned<byte[]> currentVersion = iterVersions.next();
                        returnedList.add(Pair.create(new ByteArray(key), currentVersion));
                    }
                }
            }
        }
    }
    return new KratiClosableIterator(returnedList);
}
Also used : Versioned(voldemort.versioning.Versioned) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) DataArray(krati.array.DataArray) ByteArray(voldemort.utils.ByteArray) Pair(voldemort.utils.Pair)

Aggregations

IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 DataArray (krati.array.DataArray)1 ByteArray (voldemort.utils.ByteArray)1 Pair (voldemort.utils.Pair)1 Versioned (voldemort.versioning.Versioned)1