Search in sources :

Example 56 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class HostRegexTableLoadBalancerTest method init.

public void init(Map<String, String> tableProperties) {
    HashMap<String, TableId> tables = new HashMap<>();
    tables.put(FOO.getTableName(), FOO.getId());
    tables.put(BAR.getTableName(), BAR.getId());
    tables.put(BAZ.getTableName(), BAZ.getId());
    ConfigurationCopy config = new ConfigurationCopy(SiteConfiguration.auto());
    tableProperties.forEach(config::set);
    ConfigurationImpl configImpl = new ConfigurationImpl(config);
    BalancerEnvironment environment = createMock(BalancerEnvironment.class);
    expect(environment.getConfiguration()).andReturn(configImpl).anyTimes();
    expect(environment.getTableIdMap()).andReturn(tables).anyTimes();
    expect(environment.getConfiguration(anyObject(TableId.class))).andReturn(configImpl).anyTimes();
    replay(environment);
    init(environment);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) HashMap(java.util.HashMap) ConfigurationImpl(org.apache.accumulo.core.util.ConfigurationImpl)

Example 57 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class TableLoadBalancerTest method test.

@Test
public void test() {
    BalancerEnvironment environment = createMock(BalancerEnvironment.class);
    ConfigurationCopy cc = new ConfigurationCopy(Map.of(Property.TABLE_LOAD_BALANCER.getKey(), TestSimpleLoadBalancer.class.getName()));
    ConfigurationImpl tableConfig = new ConfigurationImpl(cc);
    Map<String, TableId> tableIdMap = TABLE_ID_MAP.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> TableId.of(e.getValue())));
    expect(environment.getTableIdMap()).andReturn(tableIdMap).anyTimes();
    expect(environment.isTableOnline(anyObject(TableId.class))).andReturn(true).anyTimes();
    expect(environment.getConfiguration(anyObject(TableId.class))).andReturn(tableConfig).anyTimes();
    expect(environment.tableContext(anyObject(TableId.class))).andReturn(null).anyTimes();
    replay(environment);
    String t1Id = TABLE_ID_MAP.get("t1"), t2Id = TABLE_ID_MAP.get("t2"), t3Id = TABLE_ID_MAP.get("t3");
    state = new TreeMap<>();
    TabletServerId svr = mkts("10.0.0.1", 1234, "0x01020304");
    state.put(svr, status(t1Id, 10, t2Id, 10, t3Id, 10));
    Set<TabletId> migrations = Collections.emptySet();
    List<TabletMigration> migrationsOut = new ArrayList<>();
    TableLoadBalancer tls = new TableLoadBalancer();
    tls.init(environment);
    tls.balance(new BalanceParamsImpl(state, migrations, migrationsOut));
    assertEquals(0, migrationsOut.size());
    state.put(mkts("10.0.0.2", 2345, "0x02030405"), status());
    tls = new TableLoadBalancer();
    tls.init(environment);
    tls.balance(new BalanceParamsImpl(state, migrations, migrationsOut));
    int count = 0;
    Map<TableId, Integer> movedByTable = new HashMap<>();
    movedByTable.put(TableId.of(t1Id), 0);
    movedByTable.put(TableId.of(t2Id), 0);
    movedByTable.put(TableId.of(t3Id), 0);
    for (TabletMigration migration : migrationsOut) {
        if (migration.getOldTabletServer().equals(svr)) {
            count++;
        }
        TableId key = migration.getTablet().getTable();
        movedByTable.put(key, movedByTable.get(key) + 1);
    }
    assertEquals(15, count);
    for (Integer moved : movedByTable.values()) {
        assertEquals(5, moved.intValue());
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableId(org.apache.accumulo.core.data.TableId) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) TServerStatusImpl(org.apache.accumulo.core.manager.balancer.TServerStatusImpl) ConfigurationImpl(org.apache.accumulo.core.util.ConfigurationImpl) Text(org.apache.hadoop.io.Text) HashMap(java.util.HashMap) TabletStatistics(org.apache.accumulo.core.spi.balancer.data.TabletStatistics) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) ArrayList(java.util.ArrayList) TServerStatus(org.apache.accumulo.core.spi.balancer.data.TServerStatus) Map(java.util.Map) EasyMock.replay(org.easymock.EasyMock.replay) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EasyMock.createMock(org.easymock.EasyMock.createMock) BalanceParamsImpl(org.apache.accumulo.core.manager.balancer.BalanceParamsImpl) Property(org.apache.accumulo.core.conf.Property) EasyMock.anyObject(org.easymock.EasyMock.anyObject) TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Set(java.util.Set) TabletMigration(org.apache.accumulo.core.spi.balancer.data.TabletMigration) EasyMock.expect(org.easymock.EasyMock.expect) TabletId(org.apache.accumulo.core.data.TabletId) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) TabletServerIdImpl(org.apache.accumulo.core.manager.balancer.TabletServerIdImpl) TreeMap(java.util.TreeMap) TabletStatisticsImpl(org.apache.accumulo.core.manager.balancer.TabletStatisticsImpl) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) Collections(java.util.Collections) SortedMap(java.util.SortedMap) BalanceParamsImpl(org.apache.accumulo.core.manager.balancer.BalanceParamsImpl) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) TabletMigration(org.apache.accumulo.core.spi.balancer.data.TabletMigration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletId(org.apache.accumulo.core.data.TabletId) ConfigurationImpl(org.apache.accumulo.core.util.ConfigurationImpl) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Test(org.junit.jupiter.api.Test)

Example 58 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class ManagerClientServiceHandler method alterTableProperty.

private void alterTableProperty(TCredentials c, String tableName, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException {
    final TableId tableId = ClientServiceHandler.checkTableId(manager.getContext(), tableName, op);
    NamespaceId namespaceId = getNamespaceIdFromTableId(op, tableId);
    if (!manager.security.canAlterTable(c, tableId, namespaceId))
        throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    try {
        if (value == null || value.isEmpty()) {
            TablePropUtil.removeTableProperty(manager.getContext(), tableId, property);
        } else if (!TablePropUtil.setTableProperty(manager.getContext(), tableId, property, value)) {
            throw new Exception("Invalid table property.");
        }
    } catch (KeeperException.NoNodeException e) {
        // race condition... table no longer exists? This call will throw an exception if the table
        // was deleted:
        ClientServiceHandler.checkTableId(manager.getContext(), tableName, op);
        log.info("Error altering table property", e);
        throw new ThriftTableOperationException(tableId.canonical(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property");
    } catch (Exception e) {
        log.error("Problem altering table property", e);
        throw new ThriftTableOperationException(tableId.canonical(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property");
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TabletDeletedException(org.apache.accumulo.core.metadata.schema.TabletDeletedException) KeeperException(org.apache.zookeeper.KeeperException) TException(org.apache.thrift.TException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) KeeperException(org.apache.zookeeper.KeeperException)

Example 59 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class ManagerClientServiceHandler method waitForFlush.

@Override
public void waitForFlush(TInfo tinfo, TCredentials c, String tableIdStr, ByteBuffer startRowBB, ByteBuffer endRowBB, long flushID, long maxLoops) throws ThriftSecurityException, ThriftTableOperationException {
    TableId tableId = TableId.of(tableIdStr);
    NamespaceId namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
    if (!manager.security.canFlush(c, tableId, namespaceId))
        throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    Text startRow = ByteBufferUtil.toText(startRowBB);
    Text endRow = ByteBufferUtil.toText(endRowBB);
    if (endRow != null && startRow != null && startRow.compareTo(endRow) >= 0)
        throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.BAD_RANGE, "start row must be less than end row");
    Set<TServerInstance> serversToFlush = new HashSet<>(manager.tserverSet.getCurrentServers());
    for (long l = 0; l < maxLoops; l++) {
        for (TServerInstance instance : serversToFlush) {
            try {
                final TServerConnection server = manager.tserverSet.getConnection(instance);
                if (server != null)
                    server.flush(manager.managerLock, tableId, ByteBufferUtil.toBytes(startRowBB), ByteBufferUtil.toBytes(endRowBB));
            } catch (TException ex) {
                Manager.log.error(ex.toString());
            }
        }
        if (tableId.equals(RootTable.ID))
            // this code does not properly handle the root tablet. See #798
            break;
        if (l == maxLoops - 1)
            break;
        sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        serversToFlush.clear();
        try (TabletsMetadata tablets = TabletsMetadata.builder(manager.getContext()).forTable(tableId).overlapping(startRow, endRow).fetch(FLUSH_ID, LOCATION, LOGS, PREV_ROW).build()) {
            int tabletsToWaitFor = 0;
            int tabletCount = 0;
            for (TabletMetadata tablet : tablets) {
                int logs = tablet.getLogs().size();
                // when tablet is not online and has no logs, there is no reason to wait for it
                if ((tablet.hasCurrent() || logs > 0) && tablet.getFlushId().orElse(-1) < flushID) {
                    tabletsToWaitFor++;
                    if (tablet.hasCurrent())
                        serversToFlush.add(tablet.getLocation());
                }
                tabletCount++;
            }
            if (tabletsToWaitFor == 0)
                break;
            if (tabletCount == 0 && !manager.getContext().tableNodeExists(tableId))
                throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.NOTFOUND, null);
        } catch (TabletDeletedException e) {
            Manager.log.debug("Failed to scan {} table to wait for flush {}", MetadataTable.NAME, tableId, e);
        }
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TException(org.apache.thrift.TException) Text(org.apache.hadoop.io.Text) TabletDeletedException(org.apache.accumulo.core.metadata.schema.TabletDeletedException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) TServerConnection(org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection) TabletsMetadata(org.apache.accumulo.core.metadata.schema.TabletsMetadata) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId) HashSet(java.util.HashSet)

Example 60 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class ThriftClientHandler method setUpdateTablet.

private void setUpdateTablet(UpdateSession us, KeyExtent keyExtent) {
    long t1 = System.currentTimeMillis();
    if (us.currentTablet != null && us.currentTablet.getExtent().equals(keyExtent)) {
        return;
    }
    if (us.currentTablet == null && (us.failures.containsKey(keyExtent) || us.authFailures.containsKey(keyExtent))) {
        // if there were previous failures, then do not accept additional writes
        return;
    }
    TableId tableId = null;
    try {
        // if user has no permission to write to this table, add it to
        // the failures list
        boolean sameTable = us.currentTablet != null && us.currentTablet.getExtent().tableId().equals(keyExtent.tableId());
        tableId = keyExtent.tableId();
        if (sameTable || security.canWrite(us.getCredentials(), tableId, server.getContext().getNamespaceId(tableId))) {
            long t2 = System.currentTimeMillis();
            us.authTimes.addStat(t2 - t1);
            us.currentTablet = server.getOnlineTablet(keyExtent);
            if (us.currentTablet != null) {
                us.queuedMutations.put(us.currentTablet, new ArrayList<>());
            } else {
                // not serving tablet, so report all mutations as
                // failures
                us.failures.put(keyExtent, 0L);
                server.updateMetrics.addUnknownTabletErrors(0);
            }
        } else {
            log.warn("Denying access to table {} for user {}", keyExtent.tableId(), us.getUser());
            long t2 = System.currentTimeMillis();
            us.authTimes.addStat(t2 - t1);
            us.currentTablet = null;
            us.authFailures.put(keyExtent, SecurityErrorCode.PERMISSION_DENIED);
            server.updateMetrics.addPermissionErrors(0);
            return;
        }
    } catch (TableNotFoundException tnfe) {
        log.error("Table " + tableId + " not found ", tnfe);
        long t2 = System.currentTimeMillis();
        us.authTimes.addStat(t2 - t1);
        us.currentTablet = null;
        us.authFailures.put(keyExtent, SecurityErrorCode.TABLE_DOESNT_EXIST);
        server.updateMetrics.addUnknownTabletErrors(0);
        return;
    } catch (ThriftSecurityException e) {
        log.error("Denying permission to check user " + us.getUser() + " with user " + e.getUser(), e);
        long t2 = System.currentTimeMillis();
        us.authTimes.addStat(t2 - t1);
        us.currentTablet = null;
        us.authFailures.put(keyExtent, e.getCode());
        server.updateMetrics.addPermissionErrors(0);
        return;
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)

Aggregations

TableId (org.apache.accumulo.core.data.TableId)169 Text (org.apache.hadoop.io.Text)64 HashMap (java.util.HashMap)55 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)55 ArrayList (java.util.ArrayList)45 Test (org.junit.Test)43 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)41 Map (java.util.Map)37 Key (org.apache.accumulo.core.data.Key)36 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)34 HashSet (java.util.HashSet)31 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)31 Value (org.apache.accumulo.core.data.Value)31 IOException (java.io.IOException)28 Scanner (org.apache.accumulo.core.client.Scanner)28 AccumuloException (org.apache.accumulo.core.client.AccumuloException)27 Mutation (org.apache.accumulo.core.data.Mutation)27 List (java.util.List)26 Range (org.apache.accumulo.core.data.Range)24 BatchWriter (org.apache.accumulo.core.client.BatchWriter)23