Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EventCounter thread safe #4959

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ private static class EventCounter {
Map<String,Pair<Long,Long>> samples = new HashMap<>();
Set<String> serversUpdated = new HashSet<>();

void startingUpdates() {
synchronized void startingUpdates() {
serversUpdated.clear();
}

void updateTabletServer(String name, long sampleTime, long numEvents) {
synchronized void updateTabletServer(String name, long sampleTime, long numEvents) {
Pair<Long,Long> newSample = new Pair<>(sampleTime, numEvents);
Pair<Long,Long> lastSample = samples.get(name);

Expand All @@ -214,13 +214,13 @@ void updateTabletServer(String name, long sampleTime, long numEvents) {
serversUpdated.add(name);
}

void finishedUpdating() {
synchronized void finishedUpdating() {
// remove any tablet servers not updated
samples.keySet().retainAll(serversUpdated);
prevSamples.keySet().retainAll(serversUpdated);
}

double calculateRate() {
synchronized double calculateRate() {
double totalRate = 0;

for (Entry<String,Pair<Long,Long>> entry : prevSamples.entrySet()) {
Expand All @@ -234,7 +234,7 @@ void finishedUpdating() {
return totalRate;
}

long calculateCount() {
synchronized long calculateCount() {
long count = 0;

for (Entry<String,Pair<Long,Long>> entry : prevSamples.entrySet()) {
Expand Down