You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "adelapena (via GitHub)" <gi...@apache.org> on 2023/06/27 14:47:45 UTC

[GitHub] [cassandra] adelapena commented on a diff in pull request #2451: CASSANDRA-18494 Upgrade lucene-core library to the latest stable version

adelapena commented on code in PR #2451:
URL: https://github.com/apache/cassandra/pull/2451#discussion_r1243869553


##########
src/java/org/apache/cassandra/index/sai/disk/ResettableByteBuffersIndexOutput.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.index.sai.disk;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.lucene.store.ByteBuffersDataInput;
+import org.apache.lucene.store.ByteBuffersDataOutput;
+import org.apache.lucene.store.ByteBuffersIndexInput;
+import org.apache.lucene.store.ByteBuffersIndexOutput;
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+
+/***
+ * A wrapper around {@link ByteBuffersIndexOutput} that adds several methods that interact
+ * with the underlying delegate.
+ */
+public class ResettableByteBuffersIndexOutput extends IndexOutput
+{
+
+    private final ByteBuffersIndexOutput bbio;
+    private final ByteBuffersDataOutput delegate;
+
+    public ResettableByteBuffersIndexOutput(int expectedSize, String name)
+    {
+        super("", name);
+        delegate = new ByteBuffersDataOutput(expectedSize);
+        bbio = new ByteBuffersIndexOutput(delegate, "", name + "-bb");
+    }
+
+    public ByteBuffersDataInput toDataInput()
+    {
+        return delegate.toDataInput();
+    }
+
+    public IndexInput toIndexInput()
+    {
+        return new ByteBuffersIndexInput(toDataInput(), "");
+    }

Review Comment:
   Unused method



##########
src/java/org/apache/cassandra/index/sai/disk/oldlucene/ByteArrayIndexInput.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.index.sai.disk.oldlucene;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Locale;
+
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.RandomAccessInput;
+
+/**
+ * A {@link IndexInput} backed by a byte array.  Copied from Lucene 7.5.

Review Comment:
   I think we could add a line on the class JavaDoc saying that this comes from a previous version of Lucene. For example, `This is a copy of Lucene's ByteArrayIndexInput as it was in 7.5.0, which isn't present in the current version.`, or something like that.
   
   Also, I think even if it's a copy of Lucene's code we should use our own brace placement style (BSD vs K&R)



##########
src/java/org/apache/cassandra/index/sai/disk/ResettableByteBuffersIndexOutput.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.index.sai.disk;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.lucene.store.ByteBuffersDataInput;
+import org.apache.lucene.store.ByteBuffersDataOutput;
+import org.apache.lucene.store.ByteBuffersIndexInput;
+import org.apache.lucene.store.ByteBuffersIndexOutput;
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+
+/***
+ * A wrapper around {@link ByteBuffersIndexOutput} that adds several methods that interact
+ * with the underlying delegate.
+ */
+public class ResettableByteBuffersIndexOutput extends IndexOutput
+{
+
+    private final ByteBuffersIndexOutput bbio;
+    private final ByteBuffersDataOutput delegate;
+
+    public ResettableByteBuffersIndexOutput(int expectedSize, String name)
+    {
+        super("", name);
+        delegate = new ByteBuffersDataOutput(expectedSize);
+        bbio = new ByteBuffersIndexOutput(delegate, "", name + "-bb");
+    }
+
+    public ByteBuffersDataInput toDataInput()
+    {
+        return delegate.toDataInput();
+    }
+
+    public IndexInput toIndexInput()
+    {
+        return new ByteBuffersIndexInput(toDataInput(), "");
+    }
+
+    public void copyTo(IndexOutput out) throws IOException
+    {
+        delegate.copyTo(out);
+    }
+
+    public int intSize() {
+        return Math.toIntExact(bbio.getFilePointer());
+    }
+
+    public byte[] toArrayCopy() {
+        return delegate.toArrayCopy();
+    }
+
+    public void reset()
+    {
+        delegate.reset();
+    }
+
+    public String toString()
+    {
+        return "Resettable" + bbio.toString();
+    }
+
+    public void close() throws IOException

Review Comment:
   Nit: Starting on this one, all methods should use `@Override`



-- 
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-unsubscribe@cassandra.apache.org

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


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