start < limit
, returns a short key in [start,limit).
32 | * Simple comparator implementations should return start unchanged,
33 | */
34 | byte[] findShortestSeparator(byte[] start, byte[] limit);
35 |
36 | /**
37 | * returns a 'short key' where the 'short key' >= key.
38 | * Simple comparator implementations should return key unchanged,
39 | */
40 | byte[] findShortSuccessor(byte[] key);
41 | }
42 |
--------------------------------------------------------------------------------
/leveldb-api/src/main/java/org/iq80/leveldb/DBException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 the original author or authors.
3 | * See the notice.md file distributed with this work for additional
4 | * information regarding copyright ownership.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.iq80.leveldb;
19 |
20 | /**
21 | * @author Hiram Chirino
22 | */
23 | public class DBException
24 | extends RuntimeException
25 | {
26 | public DBException()
27 | {
28 | }
29 |
30 | public DBException(String s)
31 | {
32 | super(s);
33 | }
34 |
35 | public DBException(String s, Throwable throwable)
36 | {
37 | super(s, throwable);
38 | }
39 |
40 | public DBException(Throwable throwable)
41 | {
42 | super(throwable);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/leveldb-api/src/main/java/org/iq80/leveldb/DBFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 the original author or authors.
3 | * See the notice.md file distributed with this work for additional
4 | * information regarding copyright ownership.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.iq80.leveldb;
19 |
20 | import java.io.File;
21 | import java.io.IOException;
22 |
23 | /**
24 | * @author Hiram Chirino
25 | */
26 | public interface DBFactory
27 | {
28 | DB open(File path, Options options)
29 | throws IOException;
30 |
31 | void destroy(File path, Options options)
32 | throws IOException;
33 |
34 | void repair(File path, Options options)
35 | throws IOException;
36 | }
37 |
--------------------------------------------------------------------------------
/leveldb-api/src/main/java/org/iq80/leveldb/DBIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 the original author or authors.
3 | * See the notice.md file distributed with this work for additional
4 | * information regarding copyright ownership.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.iq80.leveldb;
19 |
20 | import java.io.Closeable;
21 | import java.util.Iterator;
22 | import java.util.Map;
23 |
24 | /**
25 | * @author Hiram Chirino
26 | */
27 | public interface DBIterator
28 | extends Iterator{key}={value}
.
179 | */
180 | @Override
181 | public String toString()
182 | {
183 | return key + "=" + value;
184 | }
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/leveldb/src/main/java/org/iq80/leveldb/impl/SequenceNumber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 the original author or authors.
3 | * See the notice.md file distributed with this work for additional
4 | * information regarding copyright ownership.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.iq80.leveldb.impl;
19 |
20 | import com.google.common.base.Preconditions;
21 |
22 | public final class SequenceNumber
23 | {
24 | // We leave eight bits empty at the bottom so a type and sequence#
25 | // can be packed together into 64-bits.
26 | public static final long MAX_SEQUENCE_NUMBER = ((0x1L << 56) - 1);
27 |
28 | private SequenceNumber()
29 | {
30 | }
31 |
32 | public static long packSequenceAndValueType(long sequence, ValueType valueType)
33 | {
34 | Preconditions.checkArgument(sequence <= MAX_SEQUENCE_NUMBER, "Sequence number is greater than MAX_SEQUENCE_NUMBER");
35 | Preconditions.checkNotNull(valueType, "valueType is null");
36 |
37 | return (sequence << 8) | valueType.getPersistentId();
38 | }
39 |
40 | public static ValueType unpackValueType(long num)
41 | {
42 | return ValueType.getValueTypeByPersistentId((byte) num);
43 | }
44 |
45 | public static long unpackSequenceNumber(long num)
46 | {
47 | return num >>> 8;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 the original author or authors.
3 | * See the notice.md file distributed with this work for additional
4 | * information regarding copyright ownership.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.iq80.leveldb.impl;
19 |
20 | import org.iq80.leveldb.Snapshot;
21 |
22 | import java.util.concurrent.atomic.AtomicBoolean;
23 |
24 | public class SnapshotImpl
25 | implements Snapshot
26 | {
27 | private final AtomicBoolean closed = new AtomicBoolean();
28 | private final Version version;
29 | private final long lastSequence;
30 |
31 | SnapshotImpl(Version version, long lastSequence)
32 | {
33 | this.version = version;
34 | this.lastSequence = lastSequence;
35 | this.version.retain();
36 | }
37 |
38 | @Override
39 | public void close()
40 | {
41 | // This is an end user API.. he might screw up and close multiple times.
42 | // but we don't want the version reference count going bad.
43 | if (closed.compareAndSet(false, true)) {
44 | this.version.release();
45 | }
46 | }
47 |
48 | public long getLastSequence()
49 | {
50 | return lastSequence;
51 | }
52 |
53 | public Version getVersion()
54 | {
55 | return version;
56 | }
57 |
58 | @Override
59 | public String toString()
60 | {
61 | return Long.toString(lastSequence);
62 | }
63 |
64 | @Override
65 | public boolean equals(Object o)
66 | {
67 | if (this == o) {
68 | return true;
69 | }
70 | if (o == null || getClass() != o.getClass()) {
71 | return false;
72 | }
73 |
74 | SnapshotImpl snapshot = (SnapshotImpl) o;
75 |
76 | if (lastSequence != snapshot.lastSequence) {
77 | return false;
78 | }
79 | if (!version.equals(snapshot.version)) {
80 | return false;
81 | }
82 |
83 | return true;
84 | }
85 |
86 | @Override
87 | public int hashCode()
88 | {
89 | int result = version.hashCode();
90 | result = 31 * result + (int) (lastSequence ^ (lastSequence >>> 32));
91 | return result;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotSeekingIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 the original author or authors.
3 | * See the notice.md file distributed with this work for additional
4 | * information regarding copyright ownership.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.iq80.leveldb.impl;
19 |
20 | import com.google.common.collect.Maps;
21 | import org.iq80.leveldb.util.AbstractSeekingIterator;
22 | import org.iq80.leveldb.util.DbIterator;
23 | import org.iq80.leveldb.util.Slice;
24 |
25 | import java.util.Comparator;
26 | import java.util.Map.Entry;
27 |
28 | public final class SnapshotSeekingIterator
29 | extends AbstractSeekingIteratorname | 36 | *offset | 37 | *length | 38 | *description | 39 | *
---|---|---|---|
entries | 44 | *4 | 45 | *vary | 46 | *Entries in order by key | 47 | *
restart index | 50 | *vary | 51 | *4 * restart count | 52 | *Index of prefix compression restarts | 53 | *
restart count | 56 | *0 | 57 | *4 | 58 | *Number of prefix compression restarts (used as index into entries) | 59 | *
name | 34 | *offset | 35 | *length | 36 | *description | 37 | *
---|---|---|---|
shared key length | 42 | *0 | 43 | *vary | 44 | *variable length encoded int: size of shared key prefix with the key from the previous entry | 45 | *
non-shared key length | 48 | *vary | 49 | *vary | 50 | *variable length encoded int: size of non-shared key suffix in this entry | 51 | *
value length | 54 | *vary | 55 | *vary | 56 | *variable length encoded int: size of value in this entry | 57 | *
non-shared key | 60 | *vary | 61 | *non-shared key length | 62 | *non-shared key data | 63 | *
value | 66 | *vary | 67 | *value length | 68 | *value data | 69 | *
A common interface for internal iterators.
25 | * 26 | * @author Hiram Chirino 27 | */ 28 | public interface InternalIterator 29 | extends SeekingIterator