minal-kyada commented on code in PR #4556:
URL: https://github.com/apache/cassandra/pull/4556#discussion_r2700224656


##########
src/java/org/apache/cassandra/service/writes/thresholds/WarnCounter.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.service.writes.thresholds;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.cassandra.locator.InetAddressAndPort;
+public class WarnCounter
+{
+    final Set<InetAddressAndPort> warnings = Collections.newSetFromMap(new 
ConcurrentHashMap<>());
+    final AtomicLong maxWarningValue = new AtomicLong();
+
+    void addWarning(InetAddressAndPort from, long value)
+    {
+        maxWarningValue.accumulateAndGet(value, Math::max);
+        warnings.add(from);

Review Comment:
   It follows the same concurrency pattern as the read flow's present 
WarnAbortCounter. 
   
   Concurrency expectation: 
   - **Writers**: Multiple n/w callback threads calling it concurrently.
   - **Reader**: Single coordinator thread calling concurrently with writers.
   
   According to me the thread safety approach would be like **update value 
first and add instance second**. 
   
   This would basically ensure the ThresholdCounter handles the `race` 
condition correctly for read and write flows both, as the comment says: 
   `call add last so concurrent reads see empty even if values > 0; if done in 
different order then size=1 could have values == 0`
   
   I can add this comment for Write flow to make this ordering explicit. Would 
that address your concern, or did you have a different concurrency scenario in 
mind ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to