Search in sources :

Example 1 with ReplicationQueueStorage

use of org.apache.hadoop.hbase.replication.ReplicationQueueStorage in project hbase by apache.

the class ReplicationBarrierCleaner method chore.

@Override
public synchronized // running instance at a time.
void chore() {
    long totalRows = 0;
    long cleanedRows = 0;
    long deletedRows = 0;
    long deletedBarriers = 0;
    long deletedLastPushedSeqIds = 0;
    TableName tableName = null;
    List<String> peerIds = null;
    try (Table metaTable = conn.getTable(TableName.META_TABLE_NAME);
        ResultScanner scanner = metaTable.getScanner(new Scan().addFamily(HConstants.REPLICATION_BARRIER_FAMILY).readAllVersions())) {
        for (; ; ) {
            Result result = scanner.next();
            if (result == null) {
                break;
            }
            totalRows++;
            long[] barriers = ReplicationBarrierFamilyFormat.getReplicationBarriers(result);
            if (barriers.length == 0) {
                continue;
            }
            byte[] regionName = result.getRow();
            TableName tn = RegionInfo.getTable(regionName);
            if (!tn.equals(tableName)) {
                tableName = tn;
                peerIds = peerManager.getSerialPeerIdsBelongsTo(tableName);
            }
            if (peerIds.isEmpty()) {
                // check if the region has already been removed, i.e, no catalog family
                if (metaTable.exists(new Get(regionName).addFamily(HConstants.CATALOG_FAMILY))) {
                    // exists, then only keep the newest barrier
                    Cell cell = result.getColumnLatestCell(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER);
                    metaTable.delete(new Delete(regionName).addFamily(HConstants.REPLICATION_BARRIER_FAMILY, cell.getTimestamp() - 1));
                    deletedBarriers += barriers.length - 1;
                } else {
                    // not exists, delete all the barriers
                    metaTable.delete(new Delete(regionName).addFamily(HConstants.REPLICATION_BARRIER_FAMILY));
                    deletedBarriers += barriers.length;
                }
                cleanedRows++;
                continue;
            }
            String encodedRegionName = RegionInfo.encodeRegionName(regionName);
            long pushedSeqId = Long.MAX_VALUE;
            for (String peerId : peerIds) {
                pushedSeqId = Math.min(pushedSeqId, peerManager.getQueueStorage().getLastSequenceId(encodedRegionName, peerId));
            }
            int index = Arrays.binarySearch(barriers, pushedSeqId);
            if (index == -1) {
                // for it.
                continue;
            }
            if (index < 0) {
                index = -index - 1;
            } else {
                index++;
            }
            // closed range and the pushedSeqId is the last barrier minus 1.
            if (index == barriers.length - 1 && pushedSeqId == barriers[barriers.length - 1] - 1) {
                // check if the region has already been removed, i.e, no catalog family
                if (!metaTable.exists(new Get(regionName).addFamily(HConstants.CATALOG_FAMILY))) {
                    ReplicationQueueStorage queueStorage = peerManager.getQueueStorage();
                    for (String peerId : peerIds) {
                        queueStorage.removeLastSequenceIds(peerId, Arrays.asList(encodedRegionName));
                        deletedLastPushedSeqIds++;
                    }
                    metaTable.delete(new Delete(regionName).addFamily(HConstants.REPLICATION_BARRIER_FAMILY));
                    deletedRows++;
                    deletedBarriers += barriers.length;
                    continue;
                }
            }
            // SerialReplicationChecker for more details.
            if (index - 1 > 0) {
                List<Cell> cells = result.getColumnCells(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER);
                // All barriers before this cell(exclusive) can be removed
                Cell cell = cells.get(cells.size() - index);
                metaTable.delete(new Delete(regionName).addFamily(HConstants.REPLICATION_BARRIER_FAMILY, cell.getTimestamp() - 1));
                cleanedRows++;
                deletedBarriers += index - 1;
            }
        }
    } catch (ReplicationException | IOException e) {
        LOG.warn("Failed to clean up replication barrier", e);
    }
    if (totalRows > 0) {
        LOG.info("TotalRows={}, cleanedRows={}, deletedRows={}, deletedBarriers={}, " + "deletedLastPushedSeqIds={}", totalRows, cleanedRows, deletedRows, deletedBarriers, deletedLastPushedSeqIds);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) TableName(org.apache.hadoop.hbase.TableName) Get(org.apache.hadoop.hbase.client.Get) Scan(org.apache.hadoop.hbase.client.Scan) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage) Cell(org.apache.hadoop.hbase.Cell)

Example 2 with ReplicationQueueStorage

use of org.apache.hadoop.hbase.replication.ReplicationQueueStorage in project hbase by apache.

the class UpdatePeerConfigProcedure method updateLastPushedSequenceIdForSerialPeer.

@Override
protected void updateLastPushedSequenceIdForSerialPeer(MasterProcedureEnv env) throws IOException, ReplicationException {
    if (!oldPeerConfig.isSerial()) {
        assert peerConfig.isSerial();
        // change to serial
        setLastPushedSequenceId(env, peerConfig);
        return;
    }
    if (!peerConfig.isSerial()) {
        // remove the serial flag
        env.getReplicationPeerManager().removeAllLastPushedSeqIds(peerId);
        return;
    }
    // enter here means peerConfig and oldPeerConfig are both serial, let's find out the diffs and
    // process them
    ReplicationQueueStorage queueStorage = env.getReplicationPeerManager().getQueueStorage();
    Connection conn = env.getMasterServices().getConnection();
    Map<String, Long> lastSeqIds = new HashMap<String, Long>();
    List<String> encodedRegionNames = new ArrayList<>();
    for (TableDescriptor td : env.getMasterServices().getTableDescriptors().getAll().values()) {
        if (!td.hasGlobalReplicationScope()) {
            continue;
        }
        TableName tn = td.getTableName();
        if (oldPeerConfig.needToReplicate(tn)) {
            if (!peerConfig.needToReplicate(tn)) {
                // removed from peer config
                for (String encodedRegionName : ReplicationBarrierFamilyFormat.getTableEncodedRegionNamesForSerialReplication(conn, tn)) {
                    addToList(encodedRegionNames, encodedRegionName, queueStorage);
                }
            }
        } else if (peerConfig.needToReplicate(tn)) {
            // newly added to peer config
            setLastPushedSequenceIdForTable(env, tn, lastSeqIds);
        }
    }
    if (!encodedRegionNames.isEmpty()) {
        queueStorage.removeLastSequenceIds(peerId, encodedRegionNames);
    }
    if (!lastSeqIds.isEmpty()) {
        queueStorage.setLastSequenceIds(peerId, lastSeqIds);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HashMap(java.util.HashMap) Connection(org.apache.hadoop.hbase.client.Connection) ArrayList(java.util.ArrayList) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 3 with ReplicationQueueStorage

use of org.apache.hadoop.hbase.replication.ReplicationQueueStorage in project hbase by apache.

the class AbstractPeerProcedure method setLastPushedSequenceIdForTable.

// Will put the encodedRegionName->lastPushedSeqId pair into the map passed in, if the map is
// large enough we will call queueStorage.setLastSequenceIds and clear the map. So the caller
// should not forget to check whether the map is empty at last, if not you should call
// queueStorage.setLastSequenceIds to write out the remaining entries in the map.
protected final void setLastPushedSequenceIdForTable(MasterProcedureEnv env, TableName tableName, Map<String, Long> lastSeqIds) throws IOException, ReplicationException {
    TableStateManager tsm = env.getMasterServices().getTableStateManager();
    ReplicationQueueStorage queueStorage = env.getReplicationPeerManager().getQueueStorage();
    Connection conn = env.getMasterServices().getConnection();
    if (!needSetLastPushedSequenceId(tsm, tableName)) {
        LOG.debug("Skip settting last pushed sequence id for {}", tableName);
        return;
    }
    for (Pair<String, Long> name2Barrier : ReplicationBarrierFamilyFormat.getTableEncodedRegionNameAndLastBarrier(conn, tableName)) {
        LOG.trace("Update last pushed sequence id for {}, {}", tableName, name2Barrier);
        addToMap(lastSeqIds, name2Barrier.getFirst(), name2Barrier.getSecond().longValue() - 1, queueStorage);
    }
}
Also used : TableStateManager(org.apache.hadoop.hbase.master.TableStateManager) Connection(org.apache.hadoop.hbase.client.Connection) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage)

Example 4 with ReplicationQueueStorage

use of org.apache.hadoop.hbase.replication.ReplicationQueueStorage in project hbase by apache.

the class DumpReplicationQueues method dumpQueues.

public String dumpQueues(ZKWatcher zkw, Set<String> peerIds, boolean hdfs) throws Exception {
    ReplicationQueueStorage queueStorage;
    StringBuilder sb = new StringBuilder();
    queueStorage = ReplicationStorageFactory.getReplicationQueueStorage(zkw, getConf());
    Set<ServerName> liveRegionServers = ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().rsZNode).stream().map(ServerName::parseServerName).collect(Collectors.toSet());
    // Loops each peer on each RS and dumps the queues
    List<ServerName> regionservers = queueStorage.getListOfReplicators();
    if (regionservers == null || regionservers.isEmpty()) {
        return sb.toString();
    }
    for (ServerName regionserver : regionservers) {
        List<String> queueIds = queueStorage.getAllQueues(regionserver);
        if (!liveRegionServers.contains(regionserver)) {
            deadRegionServers.add(regionserver.getServerName());
        }
        for (String queueId : queueIds) {
            ReplicationQueueInfo queueInfo = new ReplicationQueueInfo(queueId);
            List<String> wals = queueStorage.getWALsInQueue(regionserver, queueId);
            Collections.sort(wals);
            if (!peerIds.contains(queueInfo.getPeerId())) {
                deletedQueues.add(regionserver + "/" + queueId);
                sb.append(formatQueue(regionserver, queueStorage, queueInfo, queueId, wals, true, hdfs));
            } else {
                sb.append(formatQueue(regionserver, queueStorage, queueInfo, queueId, wals, false, hdfs));
            }
        }
    }
    return sb.toString();
}
Also used : ReplicationQueueInfo(org.apache.hadoop.hbase.replication.ReplicationQueueInfo) ServerName(org.apache.hadoop.hbase.ServerName) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage)

Example 5 with ReplicationQueueStorage

use of org.apache.hadoop.hbase.replication.ReplicationQueueStorage in project hbase by apache.

the class HBaseFsck method cleanReplicationBarrier.

public void cleanReplicationBarrier() throws IOException {
    if (!cleanReplicationBarrier || cleanReplicationBarrierTable == null) {
        return;
    }
    if (cleanReplicationBarrierTable.isSystemTable()) {
        errors.reportError(ERROR_CODE.INVALID_TABLE, "invalid table: " + cleanReplicationBarrierTable);
        return;
    }
    boolean isGlobalScope = false;
    try {
        isGlobalScope = admin.getDescriptor(cleanReplicationBarrierTable).hasGlobalReplicationScope();
    } catch (TableNotFoundException e) {
        LOG.info("we may need to clean some erroneous data due to bugs");
    }
    if (isGlobalScope) {
        errors.reportError(ERROR_CODE.INVALID_TABLE, "table's replication scope is global: " + cleanReplicationBarrierTable);
        return;
    }
    List<byte[]> regionNames = new ArrayList<>();
    Scan barrierScan = new Scan();
    barrierScan.setCaching(100);
    barrierScan.addFamily(HConstants.REPLICATION_BARRIER_FAMILY);
    barrierScan.withStartRow(ClientMetaTableAccessor.getTableStartRowForMeta(cleanReplicationBarrierTable, ClientMetaTableAccessor.QueryType.REGION)).withStopRow(ClientMetaTableAccessor.getTableStopRowForMeta(cleanReplicationBarrierTable, ClientMetaTableAccessor.QueryType.REGION));
    Result result;
    try (ResultScanner scanner = meta.getScanner(barrierScan)) {
        while ((result = scanner.next()) != null) {
            regionNames.add(result.getRow());
        }
    }
    if (regionNames.size() <= 0) {
        errors.reportError(ERROR_CODE.INVALID_TABLE, "there is no barriers of this table: " + cleanReplicationBarrierTable);
        return;
    }
    ReplicationQueueStorage queueStorage = ReplicationStorageFactory.getReplicationQueueStorage(zkw, getConf());
    List<ReplicationPeerDescription> peerDescriptions = admin.listReplicationPeers();
    if (peerDescriptions != null && peerDescriptions.size() > 0) {
        List<String> peers = peerDescriptions.stream().filter(peerConfig -> peerConfig.getPeerConfig().needToReplicate(cleanReplicationBarrierTable)).map(peerConfig -> peerConfig.getPeerId()).collect(Collectors.toList());
        try {
            List<String> batch = new ArrayList<>();
            for (String peer : peers) {
                for (byte[] regionName : regionNames) {
                    batch.add(RegionInfo.encodeRegionName(regionName));
                    if (batch.size() % 100 == 0) {
                        queueStorage.removeLastSequenceIds(peer, batch);
                        batch.clear();
                    }
                }
                if (batch.size() > 0) {
                    queueStorage.removeLastSequenceIds(peer, batch);
                    batch.clear();
                }
            }
        } catch (ReplicationException re) {
            throw new IOException(re);
        }
    }
    for (byte[] regionName : regionNames) {
        meta.delete(new Delete(regionName).addFamily(HConstants.REPLICATION_BARRIER_FAMILY));
    }
    setShouldRerun();
}
Also used : UserProvider(org.apache.hadoop.hbase.security.UserProvider) FileSystem(org.apache.hadoop.fs.FileSystem) ThreadFactoryBuilder(org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder) WALSplitUtil(org.apache.hadoop.hbase.wal.WALSplitUtil) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) FileStatus(org.apache.hadoop.fs.FileStatus) StringUtils(org.apache.commons.lang3.StringUtils) RegionState(org.apache.hadoop.hbase.master.RegionState) InetAddress(java.net.InetAddress) Future(java.util.concurrent.Future) Vector(java.util.Vector) Delete(org.apache.hadoop.hbase.client.Delete) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) ZNodePaths(org.apache.hadoop.hbase.zookeeper.ZNodePaths) AlreadyBeingCreatedException(org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException) Joiner(org.apache.hbase.thirdparty.com.google.common.base.Joiner) Closeables(org.apache.hbase.thirdparty.com.google.common.io.Closeables) EnumSet(java.util.EnumSet) Cell(org.apache.hadoop.hbase.Cell) PrintWriter(java.io.PrintWriter) ZKUtil(org.apache.hadoop.hbase.zookeeper.ZKUtil) Get(org.apache.hadoop.hbase.client.Get) Set(java.util.Set) Executors(java.util.concurrent.Executors) IOUtils(org.apache.commons.io.IOUtils) ReplicationPeerDescription(org.apache.hadoop.hbase.replication.ReplicationPeerDescription) ReplicationStorageFactory(org.apache.hadoop.hbase.replication.ReplicationStorageFactory) FutureTask(java.util.concurrent.FutureTask) Callable(java.util.concurrent.Callable) InterruptedIOException(java.io.InterruptedIOException) FsAction(org.apache.hadoop.fs.permission.FsAction) ArrayList(java.util.ArrayList) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) StoreFileInfo(org.apache.hadoop.hbase.regionserver.StoreFileInfo) ZooKeeperConnectionException(org.apache.hadoop.hbase.ZooKeeperConnectionException) ServerName(org.apache.hadoop.hbase.ServerName) Option(org.apache.hadoop.hbase.ClusterMetrics.Option) TableName(org.apache.hadoop.hbase.TableName) StringWriter(java.io.StringWriter) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Sets(org.apache.hbase.thirdparty.com.google.common.collect.Sets) IOException(java.io.IOException) ConnectionFactory(org.apache.hadoop.hbase.client.ConnectionFactory) Scan(org.apache.hadoop.hbase.client.Scan) ExecutionException(java.util.concurrent.ExecutionException) TreeMap(java.util.TreeMap) Admin(org.apache.hadoop.hbase.client.Admin) Connection(org.apache.hadoop.hbase.client.Connection) ReflectionUtils(org.apache.hadoop.util.ReflectionUtils) CatalogFamilyFormat(org.apache.hadoop.hbase.CatalogFamilyFormat) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) Result(org.apache.hadoop.hbase.client.Result) RegionLocations(org.apache.hadoop.hbase.RegionLocations) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) HFileLink(org.apache.hadoop.hbase.io.HFileLink) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage) FsPermission(org.apache.hadoop.fs.permission.FsPermission) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Configured(org.apache.hadoop.conf.Configured) TableIntegrityErrorHandler(org.apache.hadoop.hbase.util.hbck.TableIntegrityErrorHandler) Path(org.apache.hadoop.fs.Path) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) URI(java.net.URI) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) HFile(org.apache.hadoop.hbase.io.hfile.HFile) ByteArrayComparator(org.apache.hadoop.hbase.util.Bytes.ByteArrayComparator) Collection(java.util.Collection) Abortable(org.apache.hadoop.hbase.Abortable) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) HBaseInterfaceAudience(org.apache.hadoop.hbase.HBaseInterfaceAudience) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Tool(org.apache.hadoop.util.Tool) Objects(java.util.Objects) CacheConfig(org.apache.hadoop.hbase.io.hfile.CacheConfig) List(java.util.List) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) FileLink(org.apache.hadoop.hbase.io.FileLink) Entry(java.util.Map.Entry) Optional(java.util.Optional) RowMutations(org.apache.hadoop.hbase.client.RowMutations) MetaTableAccessor(org.apache.hadoop.hbase.MetaTableAccessor) RegionInfoBuilder(org.apache.hadoop.hbase.client.RegionInfoBuilder) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) SortedMap(java.util.SortedMap) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) Preconditions(org.apache.hbase.thirdparty.com.google.common.base.Preconditions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) TableState(org.apache.hadoop.hbase.client.TableState) HashSet(java.util.HashSet) InterfaceStability(org.apache.yetus.audience.InterfaceStability) HConstants(org.apache.hadoop.hbase.HConstants) HRegionFileSystem(org.apache.hadoop.hbase.regionserver.HRegionFileSystem) HFileCorruptionChecker(org.apache.hadoop.hbase.util.hbck.HFileCorruptionChecker) ReplicationChecker(org.apache.hadoop.hbase.util.hbck.ReplicationChecker) ExecutorService(java.util.concurrent.ExecutorService) KeyValue(org.apache.hadoop.hbase.KeyValue) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) KeeperException(org.apache.zookeeper.KeeperException) Put(org.apache.hadoop.hbase.client.Put) ToolRunner(org.apache.hadoop.util.ToolRunner) RegionReplicaUtil(org.apache.hadoop.hbase.client.RegionReplicaUtil) RemoteException(org.apache.hadoop.ipc.RemoteException) Lists(org.apache.hbase.thirdparty.com.google.common.collect.Lists) ClientMetaTableAccessor(org.apache.hadoop.hbase.ClientMetaTableAccessor) TimeUnit(java.util.concurrent.TimeUnit) CellUtil(org.apache.hadoop.hbase.CellUtil) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ERROR_CODE(org.apache.hadoop.hbase.util.HbckErrorReporter.ERROR_CODE) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) AccessControlException(org.apache.hadoop.security.AccessControlException) Closeable(java.io.Closeable) Table(org.apache.hadoop.hbase.client.Table) Comparator(java.util.Comparator) Collections(java.util.Collections) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Delete(org.apache.hadoop.hbase.client.Delete) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) ArrayList(java.util.ArrayList) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) Scan(org.apache.hadoop.hbase.client.Scan) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ReplicationPeerDescription(org.apache.hadoop.hbase.replication.ReplicationPeerDescription) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage)

Aggregations

ReplicationQueueStorage (org.apache.hadoop.hbase.replication.ReplicationQueueStorage)17 Test (org.junit.Test)11 ServerName (org.apache.hadoop.hbase.ServerName)6 Server (org.apache.hadoop.hbase.Server)5 TableName (org.apache.hadoop.hbase.TableName)5 ReplicationException (org.apache.hadoop.hbase.replication.ReplicationException)5 Path (org.apache.hadoop.fs.Path)4 IOException (java.io.IOException)3 FileStatus (org.apache.hadoop.fs.FileStatus)3 Connection (org.apache.hadoop.hbase.client.Connection)3 Get (org.apache.hadoop.hbase.client.Get)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 Table (org.apache.hadoop.hbase.client.Table)3 MockServer (org.apache.hadoop.hbase.util.MockServer)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Cell (org.apache.hadoop.hbase.Cell)2 ZooKeeperConnectionException (org.apache.hadoop.hbase.ZooKeeperConnectionException)2 Delete (org.apache.hadoop.hbase.client.Delete)2