belliottsmith commented on code in PR #4225:
URL: https://github.com/apache/cassandra/pull/4225#discussion_r2184503097


##########
src/java/org/apache/cassandra/service/accord/AccordTracing.java:
##########
@@ -0,0 +1,317 @@
+/*
+ * 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.accord;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.BiFunction;
+import java.util.function.Predicate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import accord.api.Tracing;
+import accord.api.TraceEventType;
+import accord.local.CommandStore;
+import accord.primitives.TxnId;
+import org.apache.cassandra.utils.Clock;
+import org.apache.cassandra.utils.NoSpamLogger;
+
+public class AccordTracing
+{
+    private static final int MAX_EVENTS = 10000;
+    private static final Logger logger = 
LoggerFactory.getLogger(AccordTracing.class);
+    private static final NoSpamLogger noSpamLogger = 
NoSpamLogger.getLogger(logger, 1L, TimeUnit.MINUTES);
+
+    public interface ConsumeState
+    {
+        void accept(TxnId txnId, TraceEventType eventType, int permits, 
List<Event> events);
+    }
+
+    public static class Message
+    {
+        public final long atNanos;
+        public final int commandStoreId;
+        public final String message;
+
+        Message(int commandStoreId, String message, long atLeastNanos)
+        {
+            this.commandStoreId = commandStoreId;
+            this.message = message;
+            this.atNanos = Math.max(atLeastNanos, Clock.Global.nanoTime());
+        }
+
+        @Override
+        public String toString()
+        {
+            return message;
+        }
+    }
+
+    public static class Event implements Tracing, Comparable<Event>
+    {
+        public final long atMicros = uniqueNowMicros();
+        public final long atNanos = Clock.Global.nanoTime();
+        final List<Message> messages = new ArrayList<>();
+
+        @Override
+        public void trace(CommandStore commandStore, String s)
+        {
+            long prevNanos = messages.isEmpty() ? 0 : 
messages.get(messages.size() - 1).atNanos;
+            int id = commandStore == null ? -1 : commandStore.id();
+            if (s.length() > 1000)
+                s = s.substring(0, 1000);
+            messages.add(new Message(id, s, prevNanos + 1));
+        }
+
+        @Override
+        public int compareTo(Event that)
+        {
+            return Long.compareUnsigned(this.atMicros, that.atMicros);
+        }
+
+        public List<Message> messages()
+        {
+            return Collections.unmodifiableList(messages);
+        }
+    }
+
+    static class TraceState extends AbstractList<Event>
+    {
+        int permits;
+        int size;
+        Event[] events;
+
+        void addInternal(Event event)
+        {
+            if (events == null) events = new Event[10];
+            else if (size == events.length) events = new Event[size * 2];

Review Comment:
   Heh, good catch



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to