-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-38888][BUILD][CORE][YARN][DOCS] Add RocksDB support for shuffle service state store
#37610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
fc388bd
e0a35c8
036d761
5154462
1aaa1ff
5804140
2191659
fed1e60
6e435b6
ce561e5
db90b27
15b2325
e124c84
4d5f44c
8907d73
097d39e
0920f0e
c76bc20
7e73ad5
8acf442
5cf1754
e068530
9e1057d
cb5148d
4d74965
96c910b
01220ed
52c1c7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.network.shuffledb; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import com.google.common.base.Throwables; | ||
| import org.rocksdb.RocksDBException; | ||
|
|
||
| /** | ||
| * RocksDB implementation of the local KV storage used to persist the shuffle state. | ||
| */ | ||
| public class RocksDB implements DB { | ||
| private final org.rocksdb.RocksDB db; | ||
|
|
||
| public RocksDB(org.rocksdb.RocksDB db) { | ||
| this.db = db; | ||
| } | ||
|
|
||
| @Override | ||
| public void put(byte[] key, byte[] value) { | ||
| try { | ||
| db.put(key, value); | ||
| } catch (RocksDBException e) { | ||
| throw Throwables.propagate(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] get(byte[] key) { | ||
| try { | ||
| return db.get(key); | ||
| } catch (RocksDBException e) { | ||
| throw Throwables.propagate(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void delete(byte[] key) { | ||
| try { | ||
| db.delete(key); | ||
| } catch (RocksDBException e) { | ||
| throw Throwables.propagate(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public DBIterator iterator() { | ||
| return new RocksDBIterator(db.newIterator()); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| db.close(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.network.shuffledb; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.AbstractMap; | ||
| import java.util.Map; | ||
| import java.util.NoSuchElementException; | ||
|
|
||
| import com.google.common.base.Throwables; | ||
| import org.rocksdb.RocksIterator; | ||
|
|
||
| /** | ||
| * RocksDB implementation of `DBIterator`. | ||
| */ | ||
| public class RocksDBIterator implements DBIterator { | ||
|
|
||
| private final RocksIterator it; | ||
|
|
||
| private boolean checkedNext; | ||
|
|
||
| private boolean closed; | ||
|
|
||
| private Map.Entry<byte[], byte[]> next; | ||
|
|
||
| public RocksDBIterator(RocksIterator it) { | ||
| this.it = it; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean hasNext() { | ||
| if (!checkedNext && !closed) { | ||
| next = loadNext(); | ||
| checkedNext = true; | ||
| } | ||
| if (!closed && next == null) { | ||
| try { | ||
|
Ngone51 marked this conversation as resolved.
Outdated
|
||
| close(); | ||
| } catch (IOException ioe) { | ||
| throw Throwables.propagate(ioe); | ||
|
Ngone51 marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| return next != null; | ||
| } | ||
|
|
||
| @Override | ||
| public Map.Entry<byte[], byte[]> next() { | ||
| if (!hasNext()) { | ||
| throw new NoSuchElementException(); | ||
| } | ||
| checkedNext = false; | ||
| Map.Entry<byte[], byte[]> ret = next; | ||
| next = null; | ||
| return ret; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| if (!closed) { | ||
| it.close(); | ||
|
Ngone51 marked this conversation as resolved.
Outdated
|
||
| closed = true; | ||
| next = null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void seek(byte[] key) { | ||
| it.seek(key); | ||
| } | ||
|
|
||
| @Override | ||
| public void remove() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering why we have a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will remove this , I found in java.util.Iterator
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| private Map.Entry<byte[], byte[]> loadNext() { | ||
| if (it.isValid()) { | ||
| Map.Entry<byte[], byte[]> nextEntry = | ||
| new AbstractMap.SimpleEntry<>(it.key(), it.value()); | ||
| it.next(); | ||
| return nextEntry; | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.