Skip to content

Commit ab6fe5c

Browse files
spkrkasduskis
authored andcommitted
---
yaml --- r: 25069 b: refs/heads/autosynth-speech c: bd8d2ce h: refs/heads/master i: 25067: 3dd38b0
1 parent 1431401 commit ab6fe5c

2 files changed

Lines changed: 8 additions & 19 deletions

File tree

  • branches/autosynth-speech/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ refs/heads/autosynth-os-login: 123ba209c5769d0ee067e0ce5848bec13b42a4f4
138138
refs/heads/autosynth-redis: 6bedce4d7c7c6ca6a22e83ad1780e08fdc565a9e
139139
refs/heads/autosynth-scheduler: 57f9fdb1e7de30c85f4ec7198931a07f50603e55
140140
refs/heads/autosynth-spanner: cbd30ccc550e9d0419ce4e5e6cfef4951ea170b1
141-
refs/heads/autosynth-speech: 03ba9c91cab9113f30bfc43d185fc87d1b515303
141+
refs/heads/autosynth-speech: bd8d2cecdfb56b35d41a86697eda279e34f19bcf
142142
refs/heads/autosynth-tasks: 5d6a4f686ffef2080506d3b613fc7563a8bba1cb
143143
refs/heads/autosynth-texttospeech: 2dcc5dc22be0f456caa1b6a8a4bcdace2641239c
144144
refs/heads/autosynth-trace: 8804c46bfe147702ee9c95669f17f42d3790cf23

branches/autosynth-speech/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,9 @@
7070
import com.google.logging.v2.WriteLogEntriesResponse;
7171
import com.google.protobuf.Empty;
7272
import java.util.ArrayList;
73-
import java.util.Collections;
74-
import java.util.IdentityHashMap;
7573
import java.util.List;
7674
import java.util.Map;
77-
import java.util.Set;
75+
import java.util.concurrent.ConcurrentHashMap;
7876
import java.util.concurrent.ExecutionException;
7977
import java.util.concurrent.TimeUnit;
8078
import java.util.concurrent.TimeoutException;
@@ -83,9 +81,7 @@ class LoggingImpl extends BaseService<LoggingOptions> implements Logging {
8381

8482
private static final int FLUSH_WAIT_TIMEOUT_SECONDS = 6;
8583
private final LoggingRpc rpc;
86-
private final Object writeLock = new Object();
87-
private final Set<ApiFuture<Void>> pendingWrites =
88-
Collections.newSetFromMap(new IdentityHashMap<ApiFuture<Void>, Boolean>());
84+
private final Map<Object, ApiFuture<Void>> pendingWrites = new ConcurrentHashMap<>();
8985

9086
private volatile Synchronicity writeSynchronicity = Synchronicity.ASYNC;
9187
private volatile Severity flushSeverity = null;
@@ -575,9 +571,7 @@ public void flush() {
575571
// BUG(1795): We should force batcher to issue RPC call for buffered messages,
576572
// so the code below doesn't wait uselessly.
577573
ArrayList<ApiFuture<Void>> writesToFlush = new ArrayList<>();
578-
synchronized (writeLock) {
579-
writesToFlush.addAll(pendingWrites);
580-
}
574+
writesToFlush.addAll(pendingWrites.values());
581575

582576
try {
583577
ApiFutures.allAsList(writesToFlush).get(FLUSH_WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
@@ -596,16 +590,13 @@ private void writeLogEntries(Iterable<LogEntry> logEntries, WriteOption... write
596590
case ASYNC:
597591
default:
598592
final ApiFuture<Void> writeFuture = writeAsync(logEntries, writeOptions);
599-
synchronized (writeLock) {
600-
pendingWrites.add(writeFuture);
601-
}
593+
final Object pendingKey = new Object();
594+
pendingWrites.put(pendingKey, writeFuture);
602595
ApiFutures.addCallback(
603596
writeFuture,
604597
new ApiFutureCallback<Void>() {
605598
private void removeFromPending() {
606-
synchronized (writeLock) {
607-
pendingWrites.remove(writeFuture);
608-
}
599+
pendingWrites.remove(pendingKey);
609600
}
610601

611602
@Override
@@ -711,8 +702,6 @@ public void close() throws Exception {
711702

712703
@VisibleForTesting
713704
int getNumPendingWrites() {
714-
synchronized (writeLock) {
715-
return pendingWrites.size();
716-
}
705+
return pendingWrites.size();
717706
}
718707
}

0 commit comments

Comments
 (0)