dcapwell commented on code in PR #4556:
URL: https://github.com/apache/cassandra/pull/4556#discussion_r2683919773


##########
src/java/org/apache/cassandra/service/writes/thresholds/CoordinatorWriteWarnings.java:
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.db.ColumnFamilyStore;
+import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.db.IMutation;
+import org.apache.cassandra.db.partitions.PartitionUpdate;
+import org.apache.cassandra.schema.Schema;
+import org.apache.cassandra.schema.TableId;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.service.ClientWarn;
+import org.apache.cassandra.utils.Pair;
+
+import io.netty.util.concurrent.FastThreadLocal;
+
+/**
+ * ThreadLocal manager for write warnings at the coordinator.
+ * Accumulates warnings from multiple write operations in a single client 
request,
+ * then sends them to the client and updates metrics.
+ */
+public class CoordinatorWriteWarnings
+{
+    private static final Logger logger = 
LoggerFactory.getLogger(CoordinatorWriteWarnings.class);
+
+    private static final Warnings INIT = new Warnings();
+    private static final Warnings EMPTY = new Warnings();
+
+    private static final FastThreadLocal<Warnings> STATE = new 
FastThreadLocal<>();
+
+    /**
+     * Initialize coordinator write warnings for this thread.
+     * Must be called at the start of a client request.
+     */
+    public static void init()
+    {
+        STATE.set(INIT);
+    }
+
+    /**
+     * Update warnings for a partition after receiving responses from replicas.
+     *
+     * @param mutation the mutation that was written
+     * @param snapshot the aggregated warnings from replicas
+     */
+    public static void update(IMutation mutation, WriteWarningsSnapshot 
snapshot)
+    {
+        if (snapshot.isEmpty())
+            return;
+
+        Warnings warnings = STATE.get();
+        if (warnings == null || warnings == EMPTY)
+            return;
+
+        for (PartitionUpdate update : mutation.getPartitionUpdates())
+        {
+            Pair<TableId, DecoratedKey> key = 
Pair.create(update.metadata().id, update.partitionKey());

Review Comment:
   using `Pair` should be discouraged here as this is a hot path.  We should 
avoid allocations as much as possible



-- 
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