提交 bba66ba7 authored 作者: Thomas Mueller's avatar Thomas Mueller

Javadocs

上级 fd988701
...@@ -1228,7 +1228,7 @@ public class TransactionStore { ...@@ -1228,7 +1228,7 @@ public class TransactionStore {
// the transaction was not committed correctly // the transaction was not committed correctly
throw DataUtils.newIllegalStateException( throw DataUtils.newIllegalStateException(
DataUtils.ERROR_TRANSACTION_CORRUPT, DataUtils.ERROR_TRANSACTION_CORRUPT,
"The transaction log might be corrupt for key {0}", "The transaction log might be corrupt for key {0}",
key); key);
} }
} else { } else {
......
...@@ -44,7 +44,7 @@ public class TestShardedMap extends TestBase { ...@@ -44,7 +44,7 @@ public class TestShardedMap extends TestBase {
assertEquals(10, map.size()); assertEquals(10, map.size());
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
assertEquals(i * 10, map.get(i).intValue()); assertEquals(i * 10, map.get(i).intValue());
} }
assertEquals("[0, 1, 2, 3, 4]", assertEquals("[0, 1, 2, 3, 4]",
a.keySet().toString()); a.keySet().toString());
assertEquals("[5, 6, 7, 8, 9]", assertEquals("[5, 6, 7, 8, 9]",
...@@ -53,7 +53,7 @@ public class TestShardedMap extends TestBase { ...@@ -53,7 +53,7 @@ public class TestShardedMap extends TestBase {
map.keySet().toString()); map.keySet().toString());
assertEquals(10, map.sizeAsLong()); assertEquals(10, map.sizeAsLong());
} }
private void testReplication() { private void testReplication() {
ShardedMap<Integer, Integer> map = new ShardedMap<Integer, Integer>(); ShardedMap<Integer, Integer> map = new ShardedMap<Integer, Integer>();
TreeMap<Integer, Integer> a = new TreeMap<Integer, Integer>(); TreeMap<Integer, Integer> a = new TreeMap<Integer, Integer>();
...@@ -66,7 +66,7 @@ public class TestShardedMap extends TestBase { ...@@ -66,7 +66,7 @@ public class TestShardedMap extends TestBase {
assertEquals(10, map.size()); assertEquals(10, map.size());
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
assertEquals(i * 10, map.get(i).intValue()); assertEquals(i * 10, map.get(i).intValue());
} }
assertEquals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]", assertEquals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]",
a.keySet().toString()); a.keySet().toString());
assertEquals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]", assertEquals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]",
...@@ -89,7 +89,7 @@ public class TestShardedMap extends TestBase { ...@@ -89,7 +89,7 @@ public class TestShardedMap extends TestBase {
assertEquals(-1, map.size()); assertEquals(-1, map.size());
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
assertEquals(i * 10, map.get(i).intValue()); assertEquals(i * 10, map.get(i).intValue());
} }
assertEquals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]", assertEquals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]",
a.keySet().toString()); a.keySet().toString());
assertEquals("[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]", assertEquals("[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]",
......
...@@ -21,10 +21,10 @@ import org.h2.util.Task; ...@@ -21,10 +21,10 @@ import org.h2.util.Task;
* A concurrent test. * A concurrent test.
*/ */
public class TestConcurrentUpdate extends TestBase { public class TestConcurrentUpdate extends TestBase {
private static final int THREADS = 3; private static final int THREADS = 3;
private static final int ROW_COUNT = 10; private static final int ROW_COUNT = 10;
/** /**
* Run just this test. * Run just this test.
* *
...@@ -42,7 +42,7 @@ public class TestConcurrentUpdate extends TestBase { ...@@ -42,7 +42,7 @@ public class TestConcurrentUpdate extends TestBase {
Connection conn = getConnection(url); Connection conn = getConnection(url);
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar)"); stat.execute("create table test(id int primary key, name varchar)");
Task[] tasks = new Task[THREADS]; Task[] tasks = new Task[THREADS];
for (int i = 0; i < THREADS; i++) { for (int i = 0; i < THREADS; i++) {
final int threadId = i; final int threadId = i;
...@@ -112,7 +112,12 @@ public class TestConcurrentUpdate extends TestBase { ...@@ -112,7 +112,12 @@ public class TestConcurrentUpdate extends TestBase {
} }
conn.close(); conn.close();
} }
/**
* Handle or ignore the exception.
*
* @param e the exception
*/
void handleException(SQLException e) throws SQLException { void handleException(SQLException e) throws SQLException {
switch (e.getErrorCode()) { switch (e.getErrorCode()) {
case ErrorCode.CONCURRENT_UPDATE_1: case ErrorCode.CONCURRENT_UPDATE_1:
......
...@@ -21,7 +21,7 @@ import org.h2.mvstore.type.ObjectDataType; ...@@ -21,7 +21,7 @@ import org.h2.mvstore.type.ObjectDataType;
/** /**
* A sharded map. It is typically split into multiple sub-maps that don't have * A sharded map. It is typically split into multiple sub-maps that don't have
* overlapping keys. * overlapping keys.
* *
* @param <K> the key type * @param <K> the key type
* @param <V> the value type * @param <V> the value type
*/ */
...@@ -38,7 +38,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -38,7 +38,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
* are applied to all maps within the range. * are applied to all maps within the range.
*/ */
private Shard<K, V>[] shards; private Shard<K, V>[] shards;
public ShardedMap() { public ShardedMap() {
this(new ObjectDataType()); this(new ObjectDataType());
} }
...@@ -48,14 +48,20 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -48,14 +48,20 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
this.keyType = keyType; this.keyType = keyType;
shards = new Shard[0]; shards = new Shard[0];
} }
public static long getSize(Map<?, ?> map) { /**
* Get the size of the map.
*
* @param map the map
* @return the size
*/
static long getSize(Map<?, ?> map) {
if (map instanceof LargeMap) { if (map instanceof LargeMap) {
return ((LargeMap) map).sizeAsLong(); return ((LargeMap) map).sizeAsLong();
} }
return map.size(); return map.size();
} }
/** /**
* Add the given shard. * Add the given shard.
* *
...@@ -76,7 +82,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -76,7 +82,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
newShards[len - 1] = newShard; newShards[len - 1] = newShard;
shards = newShards; shards = newShards;
} }
private boolean isInRange(K key, Shard<K, V> shard) { private boolean isInRange(K key, Shard<K, V> shard) {
if (shard.minIncluding != null) { if (shard.minIncluding != null) {
if (keyType.compare(key, shard.minIncluding) < 0) { if (keyType.compare(key, shard.minIncluding) < 0) {
...@@ -90,13 +96,18 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -90,13 +96,18 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
} }
return true; return true;
} }
@Override @Override
public int size() { public int size() {
long size = sizeAsLong(); long size = sizeAsLong();
return size > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) size; return size > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) size;
} }
/**
* The size of the map.
*
* @return the size
*/
public long sizeAsLong() { public long sizeAsLong() {
Shard<K, V>[] copy = shards; Shard<K, V>[] copy = shards;
for (Shard<K, V> s : copy) { for (Shard<K, V> s : copy) {
...@@ -113,7 +124,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -113,7 +124,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
} }
return -1; return -1;
} }
private boolean isSimpleSplit(Shard<K, V>[] shards) { private boolean isSimpleSplit(Shard<K, V>[] shards) {
K last = null; K last = null;
for (int i = 0; i < shards.length; i++) { for (int i = 0; i < shards.length; i++) {
...@@ -127,7 +138,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -127,7 +138,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
} }
if (s.maxExcluding == null) { if (s.maxExcluding == null) {
return i == shards.length - 1; return i == shards.length - 1;
} }
last = s.maxExcluding; last = s.maxExcluding;
} }
return last == null; return last == null;
...@@ -212,7 +223,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -212,7 +223,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
} }
} }
/** /**
* A combination of multiple sets. * A combination of multiple sets.
* *
...@@ -220,10 +231,10 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -220,10 +231,10 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
* @param <V> the value type * @param <V> the value type
*/ */
private static class CombinedSet<K, V> extends AbstractSet<Entry<K, V>> { private static class CombinedSet<K, V> extends AbstractSet<Entry<K, V>> {
final int size; final int size;
final Shard<K, V>[] shards; final Shard<K, V>[] shards;
CombinedSet(int size, Shard<K, V>[] shards) { CombinedSet(int size, Shard<K, V>[] shards) {
this.size = size; this.size = size;
this.shards = shards; this.shards = shards;
...@@ -232,12 +243,12 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -232,12 +243,12 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
@Override @Override
public Iterator<Entry<K, V>> iterator() { public Iterator<Entry<K, V>> iterator() {
return new Iterator<Entry<K, V>>() { return new Iterator<Entry<K, V>>() {
boolean init; boolean init;
Entry<K, V> current; Entry<K, V> current;
Iterator<Entry<K, V>> currentIterator; Iterator<Entry<K, V>> currentIterator;
int shardIndex; int shardIndex;
private void fetchNext() { private void fetchNext() {
while (currentIterator == null || !currentIterator.hasNext()) { while (currentIterator == null || !currentIterator.hasNext()) {
if (shardIndex >= shards.length) { if (shardIndex >= shards.length) {
...@@ -272,7 +283,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -272,7 +283,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
public void remove() { public void remove() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
}; };
} }
...@@ -280,13 +291,19 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -280,13 +291,19 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
public int size() { public int size() {
return size; return size;
} }
} }
/** /**
* A large map. * A large map.
*/ */
public interface LargeMap { public interface LargeMap {
/**
* The size of the map.
*
* @return the size
*/
long sizeAsLong(); long sizeAsLong();
} }
...@@ -295,7 +312,26 @@ public class ShardedMap<K, V> extends AbstractMap<K, V> ...@@ -295,7 +312,26 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
* given index. * given index.
*/ */
public interface CountedMap<K, V> { public interface CountedMap<K, V> {
/**
* Get the key at the given index.
*
* @param index the index
* @return the key
*/
K getKey(long index); K getKey(long index);
/**
* Get the index of the given key in the map.
* <p>
* If the key was found, the returned value is the index in the key
* array. If not found, the returned value is negative, where -1 means
* the provided key is smaller than any keys. See also
* Arrays.binarySearch.
*
* @param key the key
* @return the index
*/
long getKeyIndex(K key); long getKeyIndex(K key);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论