You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "swamirishi (via GitHub)" <gi...@apache.org> on 2023/11/17 01:44:13 UTC
[PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
swamirishi opened a new pull request, #5619:
URL: https://github.com/apache/ozone/pull/5619
## What changes were proposed in this pull request?
Snapshot list might be missing entries in the return list. Currently the list happens in a paginated fashion getting few snapshots at a time. Thus every page updates the previous value as the last entry in the previous page, helping the api to seek to the next snapshot directly. The problem is we form the listing by getting the first few entries from the cache and then the remaining entries from the table and return the concatenated list.
Consider the case:
TableCache has snap100...snap125
RocksDB Table has snap0...snap99
Now we want to list all snapshots from snap50 with maxPageSize of 30:
The expected list should be:
snap50 to snap80
But the current output is snap50 to snap54 ... snap100 to snap125 which is wrong. The next page would start from snap125, thus missing the snapshot 55 to snap100 altogether. The ideal approach would be to merge these two streams and get the snapshots in a sorted order.
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-9710
## How was this patch tested?
Existing UT. Will be adding a few more.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "hemantk-12 (via GitHub)" <gi...@apache.org>.
hemantk-12 commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1406943582
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
Review Comment:
I recently found out the OM gets crash for for unchecked exception (only certain checked exception are allowed, which is not a good idea IMO). It is OK leave it as it is for now.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "hemantk-12 (via GitHub)" <gi...@apache.org>.
hemantk-12 commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399677831
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
Review Comment:
Optional: I think it might be OK if you change `IOException` to unchecked exception (e.g. UncheckedIOException).
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1405560330
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,352 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
Review Comment:
both the iterators are in sorted order we want to get the result in sorted order by merging the iterators.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1415299917
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ if (hasNext()) {
+ HeapEntry ret = currentKey;
+ currentKey = null;
+ return ret;
+ }
+ throw new NoSuchElementException();
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
Review Comment:
done
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "hemantk-12 (via GitHub)" <gi...@apache.org>.
hemantk-12 merged PR #5619:
URL: https://github.com/apache/ozone/pull/5619
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399626615
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
+ prefixKey, startKey));
+ iteratorId++;
+ }
+ } finally {
+ omMetadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ }
+
+ // Insert the element from each of the iterator
+ for (Iterator<HeapEntry> iter : iterators) {
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+ }
+
+ }
+
+ public boolean hasNext() {
+ return !minHeap.isEmpty();
+ }
+
+ public HeapEntry next() {
+ HeapEntry heapEntry = minHeap.remove();
+ // remove the least element and
+ // reinsert the next element from the same iterator
+ Iterator<HeapEntry> iter = iterators.get(heapEntry.getEntryInteratorId());
Review Comment:
I updated the code to check if the entry is not there in the cache
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
+ prefixKey, startKey));
+ iteratorId++;
+ }
+ } finally {
+ omMetadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ }
+
+ // Insert the element from each of the iterator
+ for (Iterator<HeapEntry> iter : iterators) {
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+ }
+
+ }
+
+ public boolean hasNext() {
+ return !minHeap.isEmpty();
+ }
+
+ public HeapEntry next() {
+ HeapEntry heapEntry = minHeap.remove();
+ // remove the least element and
+ // reinsert the next element from the same iterator
+ Iterator<HeapEntry> iter = iterators.get(heapEntry.getEntryInteratorId());
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+
+ return heapEntry;
+ }
+
+ public void close() throws IOException {
+ for (ClosableIterator iterator : iterators) {
+ iterator.close();
+ }
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399616543
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
Review Comment:
OmKeyInfo & OmDirectoryInfo is iterated through the same iterator
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1408488789
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,343 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryIteratorId;
+
+ CacheIter(int entryIteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryIteratorId = entryIteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryIteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "hemantk-12 (via GitHub)" <gi...@apache.org>.
hemantk-12 commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1406951909
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
+ prefixKey, startKey));
+ iteratorId++;
+ }
+ } finally {
+ omMetadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ }
+
+ // Insert the element from each of the iterator
+ for (Iterator<HeapEntry> iter : iterators) {
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+ }
+
+ }
+
+ public boolean hasNext() {
+ return !minHeap.isEmpty();
+ }
+
+ public HeapEntry next() {
+ HeapEntry heapEntry = minHeap.remove();
+ // remove the least element and
+ // reinsert the next element from the same iterator
+ Iterator<HeapEntry> iter = iterators.get(heapEntry.getEntryInteratorId());
Review Comment:
I think it is still possible that something will be returned twice in the updated code.
Let's take the previous example, cacheTable has {e3, e4, e5} and dbTable has {e1, e2, e3, e4, e5} and page size is 3. First page would be {e1, e2, e3}. e1 and e2 are from DB and e3 from cache. When we get request for second page, cacheTable is {e4, e5, e6} and dbTable is {e1, e2, e3, e4, e5}. Second page response would be {e3, e4, e5}. e3 form DB and e4 and e5 from cache.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1407062299
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
+ prefixKey, startKey));
+ iteratorId++;
+ }
+ } finally {
+ omMetadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ }
+
+ // Insert the element from each of the iterator
+ for (Iterator<HeapEntry> iter : iterators) {
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+ }
+
+ }
+
+ public boolean hasNext() {
+ return !minHeap.isEmpty();
+ }
+
+ public HeapEntry next() {
+ HeapEntry heapEntry = minHeap.remove();
+ // remove the least element and
+ // reinsert the next element from the same iterator
+ Iterator<HeapEntry> iter = iterators.get(heapEntry.getEntryInteratorId());
Review Comment:
For the second page the next snapshot would be e3. We check if the entry is greater than e3 for the next page which would not satisfy the condition.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1405819843
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1365,66 +1365,15 @@ public List<SnapshotInfo> listSnapshot(
snapshotPrefix) ? snapshotPrefix : OM_KEY_PREFIX);
}
- TreeMap<String, SnapshotInfo> snapshotInfoMap = new TreeMap<>();
-
- int count = appendSnapshotFromCacheToMap(
- snapshotInfoMap, prefix, seek, maxListResult);
- appendSnapshotFromDBToMap(
- snapshotInfoMap, prefix, seek, count, maxListResult);
-
- return new ArrayList<>(snapshotInfoMap.values());
- }
-
- private int appendSnapshotFromCacheToMap(
- TreeMap snapshotInfoMap, String prefix,
- String previous, int maxListResult) {
- int count = 0;
- Iterator<Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>>> iterator =
- snapshotInfoTable.cacheIterator();
- while (iterator.hasNext() && count < maxListResult) {
- Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>> entry =
- iterator.next();
- String snapshotKey = entry.getKey().getCacheKey();
- SnapshotInfo snapshotInfo = entry.getValue().getCacheValue();
- if (snapshotInfo != null && snapshotKey.startsWith(prefix) &&
- snapshotKey.compareTo(previous) > 0) {
- snapshotInfoMap.put(snapshotKey, snapshotInfo);
- count++;
- }
- }
- return count;
- }
-
- private void appendSnapshotFromDBToMap(TreeMap snapshotInfoMap,
- String prefix, String previous,
- int count, int maxListResult)
- throws IOException {
- try (TableIterator<String, ? extends KeyValue<String, SnapshotInfo>>
- snapshotIter = snapshotInfoTable.iterator()) {
- KeyValue<String, SnapshotInfo> snapshotinfo;
- snapshotIter.seek(previous);
- while (snapshotIter.hasNext() && count < maxListResult) {
- snapshotinfo = snapshotIter.next();
- if (snapshotinfo != null &&
- snapshotinfo.getKey().compareTo(previous) == 0) {
- continue;
- }
- if (snapshotinfo != null && snapshotinfo.getKey().startsWith(prefix)) {
- CacheValue<SnapshotInfo> cacheValue =
- snapshotInfoTable.getCacheValue(
- new CacheKey<>(snapshotinfo.getKey()));
- // There is always the latest data in the cache, so don't need to add
- // earlier data from DB. We only add data from DB if there is no data
- // in cache.
- if (cacheValue == null) {
- snapshotInfoMap.put(snapshotinfo.getKey(), snapshotinfo.getValue());
- count++;
- }
- } else {
- break;
- }
+ List<SnapshotInfo> snapshotInfos = Lists.newArrayList();
+ try (ListIterator.MinHeapIterator snapshotIterator =
+ new ListIterator.MinHeapIterator(this, prefix, seek, volumeName,
+ bucketName, snapshotInfoTable)) {
+ while (snapshotIterator.hasNext() && maxListResult > 0) {
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399626254
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
+ prefixKey, startKey));
+ iteratorId++;
+ }
+ } finally {
+ omMetadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ }
+
+ // Insert the element from each of the iterator
+ for (Iterator<HeapEntry> iter : iterators) {
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+ }
+
+ }
+
+ public boolean hasNext() {
+ return !minHeap.isEmpty();
+ }
+
+ public HeapEntry next() {
+ HeapEntry heapEntry = minHeap.remove();
+ // remove the least element and
+ // reinsert the next element from the same iterator
+ Iterator<HeapEntry> iter = iterators.get(heapEntry.getEntryInteratorId());
Review Comment:
yeah I guess there was a bug in the previous code as well. This was being used for listing keys & dirs for FSO buckets.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "hemantk-12 (via GitHub)" <gi...@apache.org>.
hemantk-12 commented on PR #5619:
URL: https://github.com/apache/ozone/pull/5619#issuecomment-1849565359
> @aswinshakil @hemantk-12 should I merge this?
PR is good to be merged from my side. There are couple of unresolved comments form Aswin. Let him take another look and resolve them.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "hemantk-12 (via GitHub)" <gi...@apache.org>.
hemantk-12 commented on PR #5619:
URL: https://github.com/apache/ozone/pull/5619#issuecomment-1853638665
Thanks @swamirishi for the patch and @aswinshakil for the review.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "aswinshakil (via GitHub)" <gi...@apache.org>.
aswinshakil commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1406617160
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,352 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryIteratorId;
+
+ CacheIter(int entryIteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryIteratorId = entryIteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryIteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
Review Comment:
Just `CACHE` and `DB` don't need to be table specific. Generic ENUM should be fine
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1405820513
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,352 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryIteratorId;
+
+ CacheIter(int entryIteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryIteratorId = entryIteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryIteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
Review Comment:
We cannot use just one ENUM since there could be multiple table source.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "hemantk-12 (via GitHub)" <gi...@apache.org>.
hemantk-12 commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1406945297
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,343 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryIteratorId;
+
+ CacheIter(int entryIteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryIteratorId = entryIteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryIteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
Review Comment:
```suggestion
* The least element is removed i.e. a1 and then next entry from RawDir
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
Review Comment:
`NoSuchElementException` is still thrown at line 169. There is no change in that.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
+ prefixKey, startKey));
+ iteratorId++;
+ }
+ } finally {
+ omMetadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ }
+
+ // Insert the element from each of the iterator
+ for (Iterator<HeapEntry> iter : iterators) {
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+ }
+
+ }
+
+ public boolean hasNext() {
+ return !minHeap.isEmpty();
+ }
+
+ public HeapEntry next() {
+ HeapEntry heapEntry = minHeap.remove();
+ // remove the least element and
+ // reinsert the next element from the same iterator
+ Iterator<HeapEntry> iter = iterators.get(heapEntry.getEntryInteratorId());
Review Comment:
I think it is still possible that something will be returned twice in the updated code.
Let's take the previous example, cacheTable has {e3, e4, e5} and dbTable has {e1, e2, e3, e4, e5} and page size is 3. First page would be {e1, e2, e3}. e1 and e2 are from DB and e3 from cache. When we get request for second page, cacheTable is {e4, e5, e6} and dbTable is {e1, e2, e3, e4, e5}. Second page response would be {e3, e4, e5}. e3 form DB and e4 and e5 from either cache or DB.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399626805
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1405565762
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,352 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
Review Comment:
Getting the entry from cache directly
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1415272483
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneListStatusHelper.java:
##########
@@ -227,6 +208,36 @@ public Collection<OzoneFileStatus> listStatusFSO(OmKeyArgs args,
Collectors.toList());
}
+ private OzoneFileStatus getStatus(String prefixPath, long scmBlockSz,
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399618093
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399627373
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399627522
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on PR #5619:
URL: https://github.com/apache/ozone/pull/5619#issuecomment-1849538522
@aswinshakil @hemantk-12 should I merge this?
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "aswinshakil (via GitHub)" <gi...@apache.org>.
aswinshakil commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1401134221
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -1365,66 +1365,15 @@ public List<SnapshotInfo> listSnapshot(
snapshotPrefix) ? snapshotPrefix : OM_KEY_PREFIX);
}
- TreeMap<String, SnapshotInfo> snapshotInfoMap = new TreeMap<>();
-
- int count = appendSnapshotFromCacheToMap(
- snapshotInfoMap, prefix, seek, maxListResult);
- appendSnapshotFromDBToMap(
- snapshotInfoMap, prefix, seek, count, maxListResult);
-
- return new ArrayList<>(snapshotInfoMap.values());
- }
-
- private int appendSnapshotFromCacheToMap(
- TreeMap snapshotInfoMap, String prefix,
- String previous, int maxListResult) {
- int count = 0;
- Iterator<Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>>> iterator =
- snapshotInfoTable.cacheIterator();
- while (iterator.hasNext() && count < maxListResult) {
- Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>> entry =
- iterator.next();
- String snapshotKey = entry.getKey().getCacheKey();
- SnapshotInfo snapshotInfo = entry.getValue().getCacheValue();
- if (snapshotInfo != null && snapshotKey.startsWith(prefix) &&
- snapshotKey.compareTo(previous) > 0) {
- snapshotInfoMap.put(snapshotKey, snapshotInfo);
- count++;
- }
- }
- return count;
- }
-
- private void appendSnapshotFromDBToMap(TreeMap snapshotInfoMap,
- String prefix, String previous,
- int count, int maxListResult)
- throws IOException {
- try (TableIterator<String, ? extends KeyValue<String, SnapshotInfo>>
- snapshotIter = snapshotInfoTable.iterator()) {
- KeyValue<String, SnapshotInfo> snapshotinfo;
- snapshotIter.seek(previous);
- while (snapshotIter.hasNext() && count < maxListResult) {
- snapshotinfo = snapshotIter.next();
- if (snapshotinfo != null &&
- snapshotinfo.getKey().compareTo(previous) == 0) {
- continue;
- }
- if (snapshotinfo != null && snapshotinfo.getKey().startsWith(prefix)) {
- CacheValue<SnapshotInfo> cacheValue =
- snapshotInfoTable.getCacheValue(
- new CacheKey<>(snapshotinfo.getKey()));
- // There is always the latest data in the cache, so don't need to add
- // earlier data from DB. We only add data from DB if there is no data
- // in cache.
- if (cacheValue == null) {
- snapshotInfoMap.put(snapshotinfo.getKey(), snapshotinfo.getValue());
- count++;
- }
- } else {
- break;
- }
+ List<SnapshotInfo> snapshotInfos = Lists.newArrayList();
+ try (ListIterator.MinHeapIterator snapshotIterator =
+ new ListIterator.MinHeapIterator(this, prefix, seek, volumeName,
+ bucketName, snapshotInfoTable)) {
+ while (snapshotIterator.hasNext() && maxListResult > 0) {
Review Comment:
`maxListResult` is not decremented, This will do an unbounded list.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,352 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
Review Comment:
Why do we also need to compare `entryIteratorId`? I'm not getting a grasp of the ordering here.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,352 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryIteratorId;
+
+ CacheIter(int entryIteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryIteratorId = entryIteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryIteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
Review Comment:
It would be better to use Something like `CACHE` or `DB` kind of enums which was previously used for better readability.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1407057355
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,352 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryIteratorId;
+
+ CacheIter(int entryIteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryIteratorId = entryIteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryIteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
Review Comment:
We are using the same thing for file table and dir table for listing. We cannot simply do with 2 enums. The iterator id is indicator of the which iterator when has to read from to get the next entry. Heap will have only 1 entry from each iterator.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1407134700
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1405809164
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "hemantk-12 (via GitHub)" <gi...@apache.org>.
hemantk-12 commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1396666362
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
Review Comment:
nit: could be typed (e.g. Value similar to RawIter, CacheIter) rather than generic.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
Review Comment:
Can we use existing [ClosableIterator](https://github.com/apache/ozone/blob/89e6ee1ef34e71d93b0eff08f6ae58c970da5d64/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/ClosableIterator.java#L25)?
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
Review Comment:
typo: `entryIteratorId`
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
Review Comment:
nit: I would prefer to call it `DbTableIterator` or `RawIterator`.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
Review Comment:
same as previous `entryIteratorId`.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
Review Comment:
Please update a comment. Now it is not just applicable to dir and file table.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
Review Comment:
I don't think this is not needed. `hasNext()` and `next()` call this.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
Review Comment:
If `ret` is null, should we throw `NoSuchElementException`? May be something like
```
if(hasNext()) {
HeapEntry ret=currentKey;
currentKey=null;
return ret;
} else {
throw new NoSuchElementException();
}
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
Review Comment:
Do we need to check this? We have this check in [RDBStoreAbstractIterator](https://github.com/apache/ozone/blob/4b9b10f6206ed5c29c0c4957a651de1d24fe86f6/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStoreAbstractIterator.java#L99).
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
+ prefixKey, startKey));
+ iteratorId++;
+ }
+ } finally {
+ omMetadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ }
+
+ // Insert the element from each of the iterator
+ for (Iterator<HeapEntry> iter : iterators) {
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+ }
+
+ }
+
+ public boolean hasNext() {
+ return !minHeap.isEmpty();
+ }
+
+ public HeapEntry next() {
+ HeapEntry heapEntry = minHeap.remove();
+ // remove the least element and
+ // reinsert the next element from the same iterator
+ Iterator<HeapEntry> iter = iterators.get(heapEntry.getEntryInteratorId());
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+
+ return heapEntry;
+ }
+
+ public void close() throws IOException {
+ for (ClosableIterator iterator : iterators) {
+ iterator.close();
+ }
Review Comment:
```suggestion
iterators.forEach(IOUtils::closeQuietly);
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
Review Comment:
I think this should be `table`.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
+ prefixKey, startKey));
+ iteratorId++;
+ }
+ } finally {
+ omMetadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ }
+
+ // Insert the element from each of the iterator
+ for (Iterator<HeapEntry> iter : iterators) {
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+ }
+
+ }
+
+ public boolean hasNext() {
+ return !minHeap.isEmpty();
+ }
+
+ public HeapEntry next() {
+ HeapEntry heapEntry = minHeap.remove();
+ // remove the least element and
+ // reinsert the next element from the same iterator
+ Iterator<HeapEntry> iter = iterators.get(heapEntry.getEntryInteratorId());
Review Comment:
Correct me if I'm missing something but I think we are gonna return some entries twice.
For example if cacheTable has {e3, e4, e5} and dbTable has {e1, e2, e3, e4, e5} , minHeap iterator would return {e1, e2, e3, e3, e4, e4, e5, e5}.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399628457
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
Review Comment:
I guess this should be fine. handling runtime exception would require us to change other part of the code.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1405803057
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
Review Comment:
It would not be a great idea to move to unchecked exception.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1407057355
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,352 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryIteratorId;
+
+ CacheIter(int entryIteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryIteratorId = entryIteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryIteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
Review Comment:
We are using the same thing for file table and dir table for listing. We cannot simply do with 2 enums. The iterator id is indicator of the which iterator when has to read from to get the next entry. Heap will have only 1 entry from each iterator. So each table will have 2 iterators one from cache and one from DB
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "hemantk-12 (via GitHub)" <gi...@apache.org>.
hemantk-12 commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1408828513
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
Review Comment:
I recently found that OM state machine doesn't handle unchecked exception. Issues: HDDS-9685 and HDDS-9745. May be change it to checked exception or handle `NoSuchElementException` where `hasNext` is called.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
Review Comment:
nit: It is not needed. `instanceof` does the null check.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneListStatusHelper.java:
##########
@@ -227,6 +208,36 @@ public Collection<OzoneFileStatus> listStatusFSO(OmKeyArgs args,
Collectors.toList());
}
+ private OzoneFileStatus getStatus(String prefixPath, long scmBlockSz,
Review Comment:
nit: indentation is wrong. I guess check-style will fail.
```suggestion
private OzoneFileStatus getStatus(String prefixPath, long scmBlockSz,
String volumeName, String bucketName,
ReplicationConfig bucketReplication,
ListIterator.HeapEntry entry) {
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries from a given rocksDB table.
+ */
+ public static class DbTableIter<Value> implements
+ ClosableIterator {
+ private final int entryIteratorId;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ DbTableIter(int entryIteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryIteratorId = entryIteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (!KeyManagerImpl.isKeyInCache(entryKey, table)) {
+ currentKey = new HeapEntry(entryIteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ if (hasNext()) {
+ HeapEntry ret = currentKey;
+ currentKey = null;
+ return ret;
+ }
+ throw new NoSuchElementException();
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
Review Comment:
nit: There is no needed to keep `cacheIter`. You can pass it to `getCacheValues()` and initialize `cacheKeyMap`. `populateCacheMap` would be better name than `getCacheValues`
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1405819507
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "hemantk-12 (via GitHub)" <gi...@apache.org>.
hemantk-12 commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1407063284
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
+ }
+
+ private void getNextKey() throws IOException {
+ while (tableIterator.hasNext() && currentKey == null) {
+ Table.KeyValue<String, Value> entry = tableIterator.next();
+ String entryKey = entry.getKey();
+ if (entryKey.startsWith(prefixKey)) {
+ if (!KeyManagerImpl.isKeyDeleted(entryKey, table)) {
+ currentKey = new HeapEntry(entryInteratorId,
+ table.getName(), entryKey, entry.getValue());
+ }
+ } else {
+ // if the prefix key does not match, then break
+ // as the iterator is beyond the prefix.
+ break;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ return currentKey != null;
+ }
+
+ public HeapEntry next() {
+ try {
+ getNextKey();
+ } catch (Throwable t) {
+ throw new NoSuchElementException();
+ }
+ HeapEntry ret = currentKey;
+ currentKey = null;
+
+ return ret;
+ }
+
+ public void close() throws IOException {
+ tableIterator.close();
+ }
+ }
+
+ /**
+ * Iterator for Cache entries in a Dir and File Table.
+ */
+ public static class CacheIter<Value>
+ implements ClosableIterator {
+ private final Map<String, Value> cacheKeyMap;
+
+ private final Iterator<Map.Entry<String, Value>>
+ cacheCreatedKeyIter;
+ private final Iterator<Map.Entry<CacheKey<String>, CacheValue<Value>>>
+ cacheIter;
+ private final String prefixKey;
+ private final String startKey;
+ private final String tableName;
+
+ private final int entryInteratorId;
+
+ CacheIter(int entryInteratorId, String tableName,
+ Iterator<Map.Entry<CacheKey<String>,
+ CacheValue<Value>>> cacheIter, String startKey,
+ String prefixKey) {
+ this.cacheKeyMap = new TreeMap<>();
+
+ this.cacheIter = cacheIter;
+ this.startKey = startKey;
+ this.prefixKey = prefixKey;
+ this.tableName = tableName;
+ this.entryInteratorId = entryInteratorId;
+
+ getCacheValues();
+
+ cacheCreatedKeyIter = cacheKeyMap.entrySet().iterator();
+ }
+
+ private void getCacheValues() {
+ while (cacheIter.hasNext()) {
+ Map.Entry<CacheKey<String>, CacheValue<Value>> entry =
+ cacheIter.next();
+ String cacheKey = entry.getKey().getCacheKey();
+ Value cacheOmInfo = entry.getValue().getCacheValue();
+
+ // Copy cache value to local copy and work on it
+ if (cacheOmInfo instanceof CopyObject) {
+ cacheOmInfo = ((CopyObject<Value>) cacheOmInfo).copyObject();
+ }
+ if (StringUtils.isBlank(startKey)) {
+ // startKey is null or empty, then the seekKeyInDB="1024/"
+ if (cacheKey.startsWith(prefixKey)) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ } else {
+ // startKey not empty, then the seekKeyInDB="1024/b" and
+ // seekKeyInDBWithOnlyParentID = "1024/". This is to avoid case of
+ // parentID with "102444" cache entries.
+ // Here, it has to list all the keys after "1024/b" and requires >=0
+ // string comparison.
+ if (cacheKey.startsWith(prefixKey) &&
+ cacheKey.compareTo(startKey) >= 0) {
+ cacheKeyMap.put(cacheKey, cacheOmInfo);
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return cacheCreatedKeyIter.hasNext();
+ }
+
+ public HeapEntry next() {
+ Map.Entry<String, Value> entry = cacheCreatedKeyIter.next();
+ return new HeapEntry(this.entryInteratorId, this.tableName,
+ entry.getKey(), entry.getValue());
+ }
+
+ public void close() {
+ // Nothing to close here
+ }
+ }
+
+ /**
+ * Implement lexicographical sorting of the file status by sorting file status
+ * across multiple lists. Each of these lists are sorted internally.
+ *
+ * This class implements sorted output by implementing a min heap based
+ * iterator where the initial element from each of sorted list is inserted.
+ *
+ * The least entry is removed and the next entry from the same list from
+ * which the entry is removed is added into the list.
+ *
+ * For example
+ * RawDir - a1, a3, a5, a7
+ * RawFile - a2, a4, a6, a8
+ *
+ * Min Heap is initially composed of {(a1, RawDir), (a2, RawFile)}
+ * THe least element is removed i.e a1 and then next entry from RawDir
+ * is inserted into minheap resulting in {(a2, RawFile), (a3, RawDir)}
+ *
+ * This process is repeated till both the lists are exhausted.
+ */
+ public static class MinHeapIterator implements ClosableIterator {
+ private final PriorityQueue<HeapEntry> minHeap = new PriorityQueue<>();
+ private final ArrayList<ClosableIterator> iterators = new ArrayList<>();
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ BucketLayout bucketLayout, String startKey,
+ String volumeName, String bucketName) throws IOException {
+
+ this(omMetadataManager, prefixKey, startKey, volumeName,
+ bucketName, omMetadataManager.getDirectoryTable(),
+ omMetadataManager.getKeyTable(bucketLayout));
+ }
+
+ MinHeapIterator(OMMetadataManager omMetadataManager, String prefixKey,
+ String startKey, String volumeName, String bucketName,
+ Table... tables) throws IOException {
+ omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ try {
+ int iteratorId = 0;
+ for (Table table : tables) {
+ iterators.add(new CacheIter<>(iteratorId, table.getName(),
+ table.cacheIterator(), startKey, prefixKey));
+ iteratorId++;
+ iterators.add(new RawIter<>(iteratorId,
+ omMetadataManager.getDirectoryTable(),
+ prefixKey, startKey));
+ iteratorId++;
+ }
+ } finally {
+ omMetadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName,
+ bucketName);
+ }
+
+ // Insert the element from each of the iterator
+ for (Iterator<HeapEntry> iter : iterators) {
+ if (iter.hasNext()) {
+ minHeap.add(iter.next());
+ }
+ }
+
+ }
+
+ public boolean hasNext() {
+ return !minHeap.isEmpty();
+ }
+
+ public HeapEntry next() {
+ HeapEntry heapEntry = minHeap.remove();
+ // remove the least element and
+ // reinsert the next element from the same iterator
+ Iterator<HeapEntry> iter = iterators.get(heapEntry.getEntryInteratorId());
Review Comment:
Yes, you are right.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1415300398
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryIteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryIteratorId, String tableName, String key,
+ Object value) {
+ this.entryIteratorId = entryIteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryIteratorId() {
+ return this.entryIteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryIteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399615319
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
Review Comment:
The class overrides IOException close to not throw exception
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399618948
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
+ ClosableIterator {
+ private final int entryInteratorId;
+ private final String prefixKey;
+ private final TableIterator<String,
+ ? extends Table.KeyValue<String, Value>> tableIterator;
+
+ private final Table<String, Value> table;
+ private HeapEntry currentKey;
+
+ RawIter(int entryInteratorId, Table<String, Value> table,
+ String prefixKey, String startKey) throws IOException {
+ this.entryInteratorId = entryInteratorId;
+ this.table = table;
+ this.tableIterator = table.iterator(prefixKey);
+ this.prefixKey = prefixKey;
+ this.currentKey = null;
+
+ // only seek for the start key if the start key is lexicographically
+ // after the prefix key. For example
+ // Prefix key = 1024/c, Start key = 1024/a
+ // then do not seek for the start key
+ //
+ // on the other hand,
+ // Prefix key = 1024/a, Start key = 1024/c
+ // then seek for the start key
+ if (!StringUtils.isBlank(startKey) &&
+ startKey.compareTo(prefixKey) > 0) {
+ tableIterator.seek(startKey);
+ }
+
+ getNextKey();
Review Comment:
I just moved the class to another class. Didn't want to change the logic.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9710. Missing snapshot entries list Snapshot under a bucket API [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #5619:
URL: https://github.com/apache/ozone/pull/5619#discussion_r1399627756
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ListIterator.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.om;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.utils.db.CopyObject;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.PriorityQueue;
+import java.util.TreeMap;
+
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Common class to do listing of resources after merging
+ * rocksDB table cache & actual table.
+ */
+public class ListIterator {
+
+ /**
+ * Interface for iteration of Heap Entries.
+ */
+ public interface ClosableIterator extends Iterator<HeapEntry>, Closeable {
+
+ }
+
+ /**
+ * Entry to be added to the heap.
+ */
+ public static class HeapEntry implements Comparable<HeapEntry> {
+ private final int entryInteratorId;
+ private final String tableName;
+ private final String key;
+ private final Object value;
+
+ HeapEntry(int entryInteratorId, String tableName, String key,
+ Object value) {
+ this.entryInteratorId = entryInteratorId;
+ this.tableName = tableName;
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ private int getEntryInteratorId() {
+ return this.entryInteratorId;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public int compareTo(HeapEntry other) {
+ return Comparator.comparing(HeapEntry::getKey)
+ .thenComparing(HeapEntry::getEntryInteratorId).compare(this, other);
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof HeapEntry)) {
+ return false;
+ }
+
+
+ HeapEntry that = (HeapEntry) other;
+ return this.compareTo(that) == 0;
+ }
+
+ public int hashCode() {
+ return key.hashCode();
+ }
+ }
+
+ /**
+ * Iterator for DB entries in a Dir and File Table.
+ */
+ public static class RawIter<Value> implements
Review Comment:
done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org