DistributedWorkQueue bifCopyQueue = new DistributedWorkQueue( Constants.ZROOT + "/" + master.getInstanceID() + Constants.ZBULK_FAILED_COPYQ, master.getConfiguration()); continue; bifCopyQueue.addWork(orig.getName(), (failure + "," + dest).getBytes(UTF_8)); workIds.add(orig.getName()); log.debug("tid " + tid + " added to copyq: " + orig + " to " + dest + ": failed"); bifCopyQueue.waitUntilDone(workIds);
public RecoveryManager(Master master) { this.master = master; executor = Executors.newScheduledThreadPool(4, new NamingThreadFactory("Walog sort starter ")); zooCache = new ZooCache(master.getContext().getZooReaderWriter(), null); try { List<String> workIDs = new DistributedWorkQueue( master.getZooKeeperRoot() + Constants.ZRECOVERY, master.getConfiguration()) .getWorkQueued(); sortsQueued.addAll(workIDs); } catch (Exception e) { log.warn("{}", e.getMessage(), e); } }
public void startWatchingForRecoveryLogs(ThreadPoolExecutor distWorkQThreadPool) throws KeeperException, InterruptedException { this.threadPool = distWorkQThreadPool; new DistributedWorkQueue(context.getZooKeeperRoot() + Constants.ZRECOVERY, conf) .startProcessing(new LogProcessor(), this.threadPool); }
private void initiateSort(String sortId, String source, final String destination) throws KeeperException, InterruptedException { String work = source + "|" + destination; new DistributedWorkQueue(master.getZooKeeperRoot() + Constants.ZRECOVERY, master.getConfiguration()).addWork(sortId, work.getBytes(UTF_8)); synchronized (this) { sortsQueued.add(sortId); } final String path = master.getZooKeeperRoot() + Constants.ZRECOVERY + "/" + sortId; log.info("Created zookeeper entry {} with data {}", path, work); }
/** * Adds work to the queue, automatically converting the String to bytes using UTF-8 */ public void addWork(String workId, String data) throws KeeperException, InterruptedException { addWork(workId, data.getBytes(UTF_8)); }
/** * Initialize the queuedWork set with the work already sent out */ @Override protected void initializeQueuedWork() { if (queuedWork != null) { return; } queuedWork = new HashSet<>(); while (true) { try { queuedWork.addAll(workQueue.getWorkQueued()); return; } catch (KeeperException e) { if (KeeperException.Code.NONODE.equals(e.code())) { log.warn("Could not find ZK root for replication work queue, will retry", e); sleepUninterruptibly(500, TimeUnit.MILLISECONDS); continue; } log.error("Error reading existing queued replication work from ZooKeeper", e); throw new RuntimeException("Error reading existing queued replication work from ZooKeeper", e); } catch (InterruptedException e) { log.error("Error reading existing queued replication work from ZooKeeper", e); throw new RuntimeException("Error reading existing queued replication work from ZooKeeper", e); } } }
/** * Initialize the DistributedWorkQueue using the proper ZK location */ protected void initializeWorkQueue(AccumuloConfiguration conf) { workQueue = new DistributedWorkQueue( ZooUtil.getRoot(client.getInstanceID()) + ReplicationConstants.ZOO_WORK_QUEUE, conf); }
lookForWork(processor, children);
@Override public void assignWork() { if (workQueue == null) { initializeWorkQueue(conf); } initializeQueuedWork(); if (zooCache == null) { zooCache = new ZooCache(workQueue.getZooReaderWriter()); } // Get the maximum number of entries we want to queue work for (or the default) this.maxQueueSize = conf.getCount(Property.REPLICATION_MAX_WORK_QUEUE); // Scan over the work records, adding the work to the queue createWork(); // Keep the state of the work we queued correct cleanupFinishedWork(); }
private void initiateSort(String sortId, String source, final String destination, AccumuloConfiguration aconf) throws KeeperException, InterruptedException, IOException { String work = source + "|" + destination; new DistributedWorkQueue(ZooUtil.getRoot(master.getInstance()) + Constants.ZRECOVERY, aconf) .addWork(sortId, work.getBytes(UTF_8)); synchronized (this) { sortsQueued.add(sortId); } final String path = ZooUtil.getRoot(master.getInstance()) + Constants.ZRECOVERY + "/" + sortId; log.info("Created zookeeper entry " + path + " with data " + work); }
/** * Distribute the work for the given path with filename * * @param path * Path to the file being replicated * @param target * Target for the file to be replicated to */ @Override protected boolean queueWork(Path path, ReplicationTarget target) { String queueKey = DistributedWorkQueueWorkAssignerHelper.getQueueKey(path.getName(), target); if (queuedWork.contains(queueKey)) { log.debug("{} is already queued to be replicated to {}, not re-queueing", path, target); return false; } try { log.debug("Queued work for {} and {}", queueKey, path); workQueue.addWork(queueKey, path.toString()); queuedWork.add(queueKey); } catch (KeeperException | InterruptedException e) { log.warn("Could not queue work for {}", path, e); return false; } return true; }
List<String> existingWork; try { existingWork = workQueue.getWorkQueued(); } catch (KeeperException | InterruptedException e) { throw new RuntimeException("Error reading existing queued replication work", e);
/** * Initialize the DistributedWorkQueue using the proper ZK location */ protected void initializeWorkQueue(AccumuloConfiguration conf) { workQueue = new DistributedWorkQueue( ZooUtil.getRoot(conn.getInstance()) + ReplicationConstants.ZOO_WORK_QUEUE, conf); }
lookForWork(processor, children);
DistributedWorkQueue bifCopyQueue = new DistributedWorkQueue(Constants.ZROOT + "/" + HdfsZooInstance.getInstance().getInstanceID() + Constants.ZBULK_FAILED_COPYQ); continue; bifCopyQueue.addWork(orig.getName(), (failure + "," + dest).getBytes(UTF_8)); workIds.add(orig.getName()); log.debug("tid " + tid + " added to copyq: " + orig + " to " + dest + ": failed"); bifCopyQueue.waitUntilDone(workIds);
@Override public void run() { DefaultConfiguration defaultConf = DefaultConfiguration.getInstance(); long defaultDelay = defaultConf.getTimeInMillis(Property.REPLICATION_WORK_PROCESSOR_DELAY); long defaultPeriod = defaultConf.getTimeInMillis(Property.REPLICATION_WORK_PROCESSOR_PERIOD); long delay = conf.getTimeInMillis(Property.REPLICATION_WORK_PROCESSOR_DELAY); long period = conf.getTimeInMillis(Property.REPLICATION_WORK_PROCESSOR_PERIOD); try { DistributedWorkQueue workQueue; if (defaultDelay != delay && defaultPeriod != period) { log.debug("Configuration DistributedWorkQueue with delay and period of {} and {}", delay, period); workQueue = new DistributedWorkQueue( context.getZooKeeperRoot() + ReplicationConstants.ZOO_WORK_QUEUE, conf, delay, period); } else { log.debug("Configuring DistributedWorkQueue with default delay and period"); workQueue = new DistributedWorkQueue( context.getZooKeeperRoot() + ReplicationConstants.ZOO_WORK_QUEUE, conf); } workQueue.startProcessing(new ReplicationProcessor(context, conf, fs), executor); } catch (KeeperException | InterruptedException e) { throw new RuntimeException(e); } } }
public RecoveryManager(Master master) { this.master = master; executor = Executors.newScheduledThreadPool(4, new NamingThreadFactory("Walog sort starter ")); zooCache = new ZooCache(); try { List<String> workIDs = new DistributedWorkQueue(ZooUtil.getRoot(master.getInstance()) + Constants.ZRECOVERY).getWorkQueued(); sortsQueued.addAll(workIDs); } catch (Exception e) { log.warn(e, e); } }
private void initiateSort(String host, final String file) throws KeeperException, InterruptedException { String source = getSource(host, file).toString(); new DistributedWorkQueue(ZooUtil.getRoot(master.getInstance()) + Constants.ZRECOVERY).addWork(file, source.getBytes(UTF_8)); synchronized (this) { sortsQueued.add(file); } final String path = ZooUtil.getRoot(master.getInstance()) + Constants.ZRECOVERY + "/" + file; log.info("Created zookeeper entry " + path + " with data " + source); }
@Override protected boolean queueWork(Path path, ReplicationTarget target) { String queueKey = DistributedWorkQueueWorkAssignerHelper.getQueueKey(path.getName(), target); Map<Table.ID,String> workForPeer = this.queuedWorkByPeerName.get(target.getPeerName()); if (workForPeer == null) { workForPeer = new HashMap<>(); this.queuedWorkByPeerName.put(target.getPeerName(), workForPeer); } String queuedWork = workForPeer.get(target.getSourceTableId()); if (queuedWork == null) { try { workQueue.addWork(queueKey, path.toString()); workForPeer.put(target.getSourceTableId(), queueKey); } catch (KeeperException | InterruptedException e) { log.warn("Could not queue work for {} to {}", path, target, e); return false; } return true; } else if (queuedWork.startsWith(path.getName())) { log.debug("Not re-queueing work for {} as it has already been queued for replication to {}", path, target); return false; } else { log.debug("Not queueing {} for work as {} must be replicated to {} first", path, queuedWork, target.getPeerName()); return false; } }
/** * Initialize the queuedWork set with the work already sent out */ @Override protected void initializeQueuedWork() { if (null != queuedWork) { return; } queuedWork = new HashSet<>(); while (true) { try { queuedWork.addAll(workQueue.getWorkQueued()); return; } catch (KeeperException e) { if (KeeperException.Code.NONODE.equals(e.code())) { log.warn("Could not find ZK root for replication work queue, will retry", e); sleepUninterruptibly(500, TimeUnit.MILLISECONDS); continue; } log.error("Error reading existing queued replication work from ZooKeeper", e); throw new RuntimeException("Error reading existing queued replication work from ZooKeeper", e); } catch (InterruptedException e) { log.error("Error reading existing queued replication work from ZooKeeper", e); throw new RuntimeException("Error reading existing queued replication work from ZooKeeper", e); } } }