use of org.apache.hadoop.hdds.utils.db.Table.KeyValue in project ozone by apache.
the class TestTypedRDBTableStore method forEachAndIterator.
@Test
public void forEachAndIterator() throws Exception {
final int iterCount = 100;
try (Table<String, String> testTable = createTypedTable("Sixth")) {
for (int x = 0; x < iterCount; x++) {
String key = RandomStringUtils.random(10);
String value = RandomStringUtils.random(10);
testTable.put(key, value);
}
int localCount = 0;
try (TableIterator<String, ? extends KeyValue<String, String>> iter = testTable.iterator()) {
while (iter.hasNext()) {
Table.KeyValue keyValue = iter.next();
localCount++;
}
Assert.assertEquals(iterCount, localCount);
iter.seekToFirst();
iter.forEachRemaining(TestTypedRDBTableStore::consume);
Assert.assertEquals(iterCount, count);
}
}
}
use of org.apache.hadoop.hdds.utils.db.Table.KeyValue in project ozone by apache.
the class OmMetadataManagerImpl method getPendingDeletionKeys.
@Override
public List<BlockGroup> getPendingDeletionKeys(final int keyCount) throws IOException {
List<BlockGroup> keyBlocksList = Lists.newArrayList();
try (TableIterator<String, ? extends KeyValue<String, RepeatedOmKeyInfo>> keyIter = getDeletedTable().iterator()) {
int currentCount = 0;
while (keyIter.hasNext() && currentCount < keyCount) {
KeyValue<String, RepeatedOmKeyInfo> kv = keyIter.next();
if (kv != null) {
RepeatedOmKeyInfo infoList = kv.getValue();
// Get block keys as a list.
for (OmKeyInfo info : infoList.getOmKeyInfoList()) {
OmKeyLocationInfoGroup latest = info.getLatestVersionLocations();
List<BlockID> item = latest.getLocationList().stream().map(b -> new BlockID(b.getContainerID(), b.getLocalID())).collect(Collectors.toList());
BlockGroup keyBlocks = BlockGroup.newBuilder().setKeyName(kv.getKey()).addAllBlockIDs(item).build();
keyBlocksList.add(keyBlocks);
currentCount++;
}
}
}
}
return keyBlocksList;
}
Aggregations