Search in sources :

Example 1 with TabletLocations

use of org.apache.accumulo.core.client.impl.TabletLocator.TabletLocations in project accumulo by apache.

the class MetadataLocationObtainer method getMetadataLocationEntries.

public static TabletLocations getMetadataLocationEntries(SortedMap<Key, Value> entries) {
    Key key;
    Value val;
    Text location = null;
    Text session = null;
    Value prevRow = null;
    KeyExtent ke;
    List<TabletLocation> results = new ArrayList<>();
    ArrayList<KeyExtent> locationless = new ArrayList<>();
    Text lastRowFromKey = new Text();
    // text obj below is meant to be reused in loop for efficiency
    Text colf = new Text();
    Text colq = new Text();
    for (Entry<Key, Value> entry : entries.entrySet()) {
        key = entry.getKey();
        val = entry.getValue();
        if (key.compareRow(lastRowFromKey) != 0) {
            prevRow = null;
            location = null;
            session = null;
            key.getRow(lastRowFromKey);
        }
        colf = key.getColumnFamily(colf);
        colq = key.getColumnQualifier(colq);
        // interpret the row id as a key extent
        if (colf.equals(TabletsSection.CurrentLocationColumnFamily.NAME) || colf.equals(TabletsSection.FutureLocationColumnFamily.NAME)) {
            if (location != null) {
                throw new IllegalStateException("Tablet has multiple locations : " + lastRowFromKey);
            }
            location = new Text(val.toString());
            session = new Text(colq);
        } else if (TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.equals(colf, colq)) {
            prevRow = new Value(val);
        }
        if (prevRow != null) {
            ke = new KeyExtent(key.getRow(), prevRow);
            if (location != null)
                results.add(new TabletLocation(ke, location.toString(), session.toString()));
            else
                locationless.add(ke);
            location = null;
            prevRow = null;
        }
    }
    return new TabletLocations(results, locationless);
}
Also used : TabletLocations(org.apache.accumulo.core.client.impl.TabletLocator.TabletLocations) TabletLocation(org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation) Value(org.apache.accumulo.core.data.Value) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Aggregations

ArrayList (java.util.ArrayList)1 TabletLocation (org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation)1 TabletLocations (org.apache.accumulo.core.client.impl.TabletLocator.TabletLocations)1 Key (org.apache.accumulo.core.data.Key)1 PartialKey (org.apache.accumulo.core.data.PartialKey)1 Value (org.apache.accumulo.core.data.Value)1 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)1 Text (org.apache.hadoop.io.Text)1