Skip to content

Commit

Permalink
[MINOR] Introduce a method for acquiring the number of data in local …
Browse files Browse the repository at this point in the history
…Tablets (#173)
  • Loading branch information
yunseong authored and wynot12 committed May 16, 2017
1 parent 3b5a56f commit b4a50f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,9 @@ public interface Tablet<K, V, U> {
* @return an iterator of {@link Entry} of local data key-value pairs
*/
Iterator<Entry<K, V>> getDataIterator();

/**
* @return the number of local data items existing in the Tablet.
*/
int getNumDataItems();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
@EvaluatorSide
@ThreadSafe
public final class TabletImpl<K, V, U> implements Tablet<K, V, U> {

/**
* Local blocks which this executor owns.
*/
Expand Down Expand Up @@ -158,4 +159,23 @@ public Entry<K, V> next() {
}
};
}

@Override
public int getNumDataItems() {
int numTotal = 0;

// will not care blocks migrated in after this call
final List<Integer> localBlockIds = ownershipCache.getCurrentLocalBlockIds();

for (final Integer blockId : localBlockIds) {
try {
final Block<K, V, U> block = blockStore.get(blockId);
numTotal += block.getNumPairs();
} catch (final BlockNotExistsException e) {
// This block has moved out to another executor, but it is safe to ignore it in counting the number of items.
}
}

return numTotal;
}
}

0 comments on commit b4a50f7

Please sign in to comment.