maedhroz commented on code in PR #3539:
URL: https://github.com/apache/cassandra/pull/3539#discussion_r1759388209


##########
src/java/org/apache/cassandra/dht/OwnedRanges.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.dht;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.apache.cassandra.metrics.StorageMetrics;
+import org.apache.cassandra.service.StorageService;
+
+public final class OwnedRanges
+{
+    private static final Logger logger = 
LoggerFactory.getLogger(OwnedRanges.class);
+
+    private static final Comparator<Range<Token>> rangeComparator = 
Comparator.comparing((Range<Token> r) -> r.left).thenComparing(r -> r.right);
+
+    // the set of token ranges that this node is a replica for
+    private final List<Range<Token>> ownedRanges;
+
+    public OwnedRanges(Collection<Range<Token>> ownedRanges)
+    {
+        this.ownedRanges = Range.normalize(ownedRanges);
+    }
+
+    /**
+     * Check that all ranges in a requested set are contained by those in the 
owned set. Used in several contexts, such
+     * as validating StreamRequests in StreamSession & PrepareMessage and 
ValidationRequest in RepairMessageVerbHandler.
+     * In those callers, we want to verify that the token ranges specified in 
some request from a peer are not outside
+     * the ranges owned by the local node. There are 2 levels of response if 
invalid ranges are detected, controlled
+     * by options in Config; logging the event and rejecting the request and 
either/neither/both of these options may be
+     * enabled. If neither are enabled, we short ciruit and immediately return 
success without any further processing.
+     * If either option is enabled, and we do detect unowned ranges in the 
request, we increment a metric then take further
+     * action depending on the config.
+     *
+     * @param requestedRanges the set of token ranges contained in a request 
from a peer
+     * @param requestId an identifier for the peer request, to be used in 
logging (e.g. Stream or Repair Session #)
+     * @param requestType description of the request type, to be used in 
logging (e.g. "prepare request" or "validation")
+     * @param from the originator of the request
+     * @return true if the request should be accepted (either because no 
checking was performed, invalid ranges were d
+     *         identified but only the logging action is enabled, or because 
all request ranges were valid. Otherwise,
+     *         returns false to indicate the request should be rejected.

Review Comment:
   Should read...
   
   ```
   * @return true if the request should be accepted (either because no checking 
was performed, invalid ranges were 
   *         identified but only the logging action is enabled, or because all 
request ranges were valid).
   *         Otherwise, returns false to indicate the request should be 
rejected.
   ```



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