Search in sources :

Example 21 with AccumuloException

use of org.apache.accumulo.core.client.AccumuloException in project gora by apache.

the class AccumuloStore method getPartitions.

@Override
public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
    try {
        TabletLocator tl;
        if (conn instanceof MockConnector)
            tl = new MockTabletLocator();
        else
            tl = TabletLocator.getLocator(new ClientContext(conn.getInstance(), credentials, AccumuloConfiguration.getTableConfiguration(conn, Tables.getTableId(conn.getInstance(), mapping.tableName))), new Text(Tables.getTableId(conn.getInstance(), mapping.tableName)));
        Map<String, Map<KeyExtent, List<Range>>> binnedRanges = new HashMap<>();
        tl.invalidateCache();
        while (tl.binRanges(new ClientContext(conn.getInstance(), credentials, AccumuloConfiguration.getTableConfiguration(conn, Tables.getTableId(conn.getInstance(), mapping.tableName))), Collections.singletonList(createRange(query)), binnedRanges).size() > 0) {
            // TODO log?
            if (!Tables.exists(conn.getInstance(), Tables.getTableId(conn.getInstance(), mapping.tableName)))
                throw new TableDeletedException(Tables.getTableId(conn.getInstance(), mapping.tableName));
            else if (Tables.getTableState(conn.getInstance(), Tables.getTableId(conn.getInstance(), mapping.tableName)) == TableState.OFFLINE)
                throw new TableOfflineException(conn.getInstance(), Tables.getTableId(conn.getInstance(), mapping.tableName));
            UtilWaitThread.sleep(100);
            tl.invalidateCache();
        }
        List<PartitionQuery<K, T>> ret = new ArrayList<>();
        Text startRow = null;
        Text endRow = null;
        if (query.getStartKey() != null)
            startRow = new Text(toBytes(query.getStartKey()));
        if (query.getEndKey() != null)
            endRow = new Text(toBytes(query.getEndKey()));
        //hadoop expects hostnames, accumulo keeps track of IPs... so need to convert
        HashMap<String, String> hostNameCache = new HashMap<>();
        for (Entry<String, Map<KeyExtent, List<Range>>> entry : binnedRanges.entrySet()) {
            String ip = entry.getKey().split(":", 2)[0];
            String location = hostNameCache.get(ip);
            if (location == null) {
                InetAddress inetAddress = InetAddress.getByName(ip);
                location = inetAddress.getHostName();
                hostNameCache.put(ip, location);
            }
            Map<KeyExtent, List<Range>> tablets = entry.getValue();
            for (KeyExtent ke : tablets.keySet()) {
                K startKey = null;
                if (startRow == null || !ke.contains(startRow)) {
                    if (ke.getPrevEndRow() != null) {
                        startKey = followingKey(encoder, getKeyClass(), getBytes(ke.getPrevEndRow()));
                    }
                } else {
                    startKey = fromBytes(getKeyClass(), getBytes(startRow));
                }
                K endKey = null;
                if (endRow == null || !ke.contains(endRow)) {
                    if (ke.getEndRow() != null)
                        endKey = lastPossibleKey(encoder, getKeyClass(), getBytes(ke.getEndRow()));
                } else {
                    endKey = fromBytes(getKeyClass(), getBytes(endRow));
                }
                PartitionQueryImpl<K, T> pqi = new PartitionQueryImpl<>(query, startKey, endKey, location);
                pqi.setConf(getConf());
                ret.add(pqi);
            }
        }
        return ret;
    } catch (TableNotFoundException | AccumuloException | AccumuloSecurityException e) {
        throw new IOException(e);
    }
}
Also used : TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MockTabletLocator(org.apache.accumulo.core.client.mock.impl.MockTabletLocator) AccumuloException(org.apache.accumulo.core.client.AccumuloException) PartitionQueryImpl(org.apache.gora.query.impl.PartitionQueryImpl) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) MockTabletLocator(org.apache.accumulo.core.client.mock.impl.MockTabletLocator) TabletLocator(org.apache.accumulo.core.client.impl.TabletLocator) MockConnector(org.apache.accumulo.core.client.mock.MockConnector) Map(java.util.Map) HashMap(java.util.HashMap) PartitionQuery(org.apache.gora.query.PartitionQuery) InetAddress(java.net.InetAddress)

Aggregations

AccumuloException (org.apache.accumulo.core.client.AccumuloException)21 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)15 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)14 IOException (java.io.IOException)7 Entry (java.util.Map.Entry)7 BatchWriter (org.apache.accumulo.core.client.BatchWriter)7 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)7 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)7 Key (org.apache.accumulo.core.data.Key)7 Mutation (org.apache.accumulo.core.data.Mutation)7 Value (org.apache.accumulo.core.data.Value)7 Authorizations (org.apache.accumulo.core.security.Authorizations)7 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)7 Edge (uk.gov.gchq.gaffer.data.element.Edge)7 Element (uk.gov.gchq.gaffer.data.element.Element)7 Scanner (org.apache.accumulo.core.client.Scanner)6 Text (org.apache.hadoop.io.Text)6 IteratorSettingBuilder (uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder)6 Connector (org.apache.accumulo.core.client.Connector)5 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)4