public PullLog get(final String subject, final String group, final String consumerId) { String groupAndSubject = groupAndSubject(subject, group); synchronized (logs) { return logs.get(consumerId, groupAndSubject); } }
public static GroupAndSubject parse(String groupAndSubject) { String[] arr = groupAndSubject.split(GROUP_INDEX_DELIM); return new GroupAndSubject(arr[1], arr[0]); }
Subscriber(SubscriberStatusChecker checker, String name, String consumerId) { this.checker = checker; this.name = name; final GroupAndSubject groupAndSubject = GroupAndSubject.parse(name); this.group = groupAndSubject.getGroup(); this.subject = groupAndSubject.getSubject(); this.consumerId = consumerId; this.lastUpdate = System.currentTimeMillis(); }
public Subscriber getSubscriber(String subject, String group, String consumerId) { final String groupAndSubject = GroupAndSubject.groupAndSubject(subject, group); final ConcurrentMap<String, Subscriber> m = subscribers.get(groupAndSubject); if (m == null) { return null; } return m.get(consumerId); }
private void cleanPullLogAndCheckpoint() { final Table<String, String, PullLog> pullLogs = storage.allPullLogs(); if (pullLogs == null || pullLogs.size() == 0) return; // delete all pull log without max pulled message sequence for (final String groupAndSubject : pullLogs.columnKeySet()) { final GroupAndSubject gs = GroupAndSubject.parse(groupAndSubject); final long maxPulledMessageSequence = storage.getMaxPulledMessageSequence(gs.getSubject(), gs.getGroup()); if (maxPulledMessageSequence == -1) { for (final Map.Entry<String, PullLog> entry : pullLogs.column(groupAndSubject).entrySet()) { final String consumerId = entry.getKey(); LOG.info("remove pull log. subject: {}, group: {}, consumerId: {}", gs.getSubject(), gs.getGroup(), consumerId); storage.destroyPullLog(gs.getSubject(), gs.getGroup(), consumerId); } } } }
private void remove(String subject, String group, String consumerId) { String groupAndSubject = groupAndSubject(subject, group); synchronized (logs) { logs.remove(consumerId, groupAndSubject); } }
public void addSubscriber(String subject, String group, String consumerId) { final String groupAndSubject = GroupAndSubject.groupAndSubject(subject, group); addSubscriber(groupAndSubject, consumerId); }
private boolean noPullLog(String subject, String group, String consumerId) { Table<String, String, PullLog> pullLogs = storage.allPullLogs(); Map<String, PullLog> subscribers = pullLogs.row(consumerId); if (subscribers == null || subscribers.isEmpty()) return true; return subscribers.get(GroupAndSubject.groupAndSubject(subject, group)) == null; }
public PullLog getOrCreate(final String subject, final String group, final String consumerId) { final String groupAndSubject = groupAndSubject(subject, group); synchronized (logs) { if (!logs.contains(consumerId, groupAndSubject)) { logs.put(consumerId, groupAndSubject, new PullLog(config, consumerId, groupAndSubject)); } return logs.get(consumerId, groupAndSubject); } }
private void initSubscribers() { final Collection<ConsumerGroupProgress> progresses = storage.allConsumerGroupProgresses(); progresses.forEach(progress -> { if (progress.isBroadcast()) { return; } progress.getConsumers().values().forEach(consumer -> { final String groupAndSubject = GroupAndSubject.groupAndSubject(consumer.getSubject(), consumer.getGroup()); addSubscriber(groupAndSubject, consumer.getConsumerId()); }); }); }
private void fixActionCheckpoint(PullLogManager manager) { final Table<String, String, PullLog> allLogs = manager.getLogs(); final Table<String, String, ConsumerGroupProgress> progresses = actionCheckpoint.getProgresses(); progresses.values().forEach(progress -> { final String subject = progress.getSubject(); final String group = progress.getGroup(); final String groupAndSubject = GroupAndSubject.groupAndSubject(subject, group); final Map<String, ConsumerProgress> consumers = progress.getConsumers(); final Map<String, PullLog> logs = allLogs.column(groupAndSubject); logs.forEach((consumerId, log) -> { final long pull = log.getMaxOffset() - 1; final ConsumerProgress consumer = consumers.get(consumerId); if (consumer != null) { consumer.setPull(pull); } else { consumers.put(consumerId, new ConsumerProgress(subject, group, consumerId, pull, -1)); } }); if (consumers.size() == 1) { consumers.values().forEach(consumer -> { if (consumer.getPull() < 0) { progress.setBroadcast(true); consumer.setPull(progress.getPull()); } }); } }); }