Top Description Inners Fields Constructors Methods
org.h2.mvstore

public final Class MVStore

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Imports
java.lang.Thread.UncaughtExceptionHandler, java.util.ArrayList, .Arrays, .Deque, .HashMap, .HashSet, .Iterator, .LinkedList, .Locale, .Map, .Set, java.util.concurrent.Callable, .ConcurrentHashMap, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean, .AtomicInteger, .AtomicIntegerFieldUpdater, .AtomicLong, java.util.concurrent.locks.ReentrantLock, java.util.function.BiConsumer, .LongConsumer, .Predicate, org.h2.compress.CompressDeflate, .CompressLZF, .Compressor, org.h2.mvstore.type.StringDataType, org.h2.store.fs.FileUtils, org.h2.util.Utils

A persistent storage for maps.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
MVStore.Builder

A builder for an MVStore.

public static class
MVStore.TxCounter

Class TxCounter is a simple data structure to hold version of the store along with the counter of open transactions, which are still operating on this version.

Field Summary

Modifier and TypeField and Description
private final int
public final Thread.UncaughtExceptionHandler
private final int
compressionLevel

The compression level for new pages (0 for disabled, 1 for fast, 2 for high).

private Compressor
private Compressor
private volatile MVStore.TxCounter
currentTxCounter

Counter of open transactions for the latest (current) store version

private volatile long
private final FileStore<?>
private final boolean
pack-priv static final long
INITIAL_VERSION

This designates the "last stored" version for a store which was just open for the first time.

private final int
private final AtomicInteger
private long
private long
private final ConcurrentHashMap<Integer, MVMap<?, ?>>
private final MVMap<String, String>
meta

The metadata map.

private volatile boolean
private long
private final AtomicLong
oldestVersionToKeep

Oldest store version in use.

private volatile LongConsumer
oldestVersionTracker

Callback for maintenance after some unused store versions were dropped

private volatile MVStoreException
private volatile boolean
private volatile int
private static final int
STATE_CLOSED

Store is closed.

private static final int
STATE_OPEN

Store is open.

private static final int
STATE_STOPPING

Store is about to close now, but is still operational.

private final ReentrantLock
storeLock

Lock which governs access to major store operations: store(), close(), ...

private final AtomicBoolean
storeOperationInProgress

Flag to refine the state under storeLock.

private int
unsavedMemory

The estimated memory used by unsaved pages.

private long
private long
private final Deque<MVStore.TxCounter>
versions

Ordered collection of all version usage counters for all versions starting from oldestVersionToKeep and up to current.

private int

Constructor Summary

AccessConstructor and Description
pack-priv
MVStore(Map<String, Object>
the configuration to use
config
)

Create and open the store.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
accountForRemovedPage(long
the position of the page
pos
,
long
at which page was removed
version
,
boolean
whether page is considered pinned
pinned
,
int
sequential page number within chunk
pageNo
)

Remove a page.

pack-priv void
adjustLastMapId(int mapId)

pack-priv void
beforeWrite(MVMap<?, ?>
the map
map
)

This method is called before writing to a map.

private boolean
private void
private void
public void
close()

Implements java.lang.AutoCloseable.close.

Close the file and the store.

public void
close(int
time (in milliseconds) allotted for file compaction activity, 0 means no compaction, -1 means unlimited time (full compaction)
allowedCompactionTime
)

Close the store.

public void
closeImmediately()

Close the file and the store, without writing anything.

private void
closeStore(boolean normalShutdown, int allowedCompactionTime)

private ArrayList<Page<?, ?>>
collectChangedMapRoots(long version)

public long

Returns:

the new version (incremented if there were changes) or -1 if there were no commit
commit
()

Commit the changes.

private long
public boolean

Returns:

if any chunk was re-written
compact
(int
the minimum percentage of live entries
targetFillRate
,
int
the minimum number of bytes to write
write
)

Try to increase the fill rate by re-writing partially full chunks.

public void
compactFile(int
the maximum time in milliseconds to compact
maxCompactTime
)

Compact store file, that is, compact blocks that have a low fill rate, and move chunks next to each other.

public void
countNewPage(boolean leaf)

public boolean

Returns:

true if counter reaches zero, which indicates that version is no longer in use, false otherwise.
decrementVersionUsageCounter
(MVStore.TxCounter
to be decremented, obtained from registerVersionUsage()
txCounter
)

De-register (close) completed operation (transaction).

pack-priv void
deregisterMapRoot(int
to deregister
mapId
)

Performs final stage of map removal - delete root location info from the layout table.

public void
deregisterVersionUsage(MVStore.TxCounter
to be decremented, obtained from registerVersionUsage()
txCounter
)

De-register (close) completed operation (transaction).

private void
public void
public int

Returns:

the delay in milliseconds, or 0 if auto-commit is disabled.
getAutoCommitDelay
()

Get the auto-commit delay.

public int

Returns:

the memory in bytes
getAutoCommitMemory
()

Get the maximum memory (in bytes) used for unsaved pages.

public int

Returns:

the cache size
getCacheSize
()

Get the maximum cache size, in MB.

public int

Returns:

the amount of memory used for caching
getCacheSizeUsed
()

Get the amount of memory used for caching, in MB.

pack-priv int
pack-priv Compressor
pack-priv Compressor
public long

Returns:

the version
getCurrentVersion
()

Get the current version of the data.

public FileStore<?>

Returns:

the file store
getFileStore
()

Get the file store.

public int
public int
pack-priv int
public Map<String, String>

Returns:

the metadata map
getLayoutMap
()

Get this store's layout map.

private int
public <
the key type
K
,
the value type
V
>
MVMap<K, V>

Returns:

Map
getMap
(int
map id
id
)

Get map by id.

private int
public String

Returns:

the name, or null if not found
getMapName
(int
the map id
id
)

Get the name of the given map.

public Set<String>

Returns:

the set of names
getMapNames
()

Get the set of all map names.

public long
public MVMap<String, String>

Returns:

the metadata map
getMetaMap
()

Get the metadata map.

private int
pack-priv long

Returns:

the version
getOldestVersionToKeep
()

Get the oldest version to retain.

public MVStoreException
public int
private long
getRootPos(int mapId)

public Map<String, Object>

Returns:

the store header
getStoreHeader
()

Get the store header.

public int

Returns:

the store version
getStoreVersion
()

Get the store version.

public long
public int

Returns:

the memory in bytes
getUnsavedMemory
()

Get the estimated memory (in bytes) of unsaved data.

private double
public long

Returns:

the version
getVersionsToKeep
()

Get the oldest version to retain in memory (for in-memory stores).

pack-priv boolean
public boolean

Returns:

true if it exists and has data.
hasData
(String
the map name
name
)

Check whether a given map exists and has data.

public boolean

Returns:

true if it exists
hasMap
(String
the map name
name
)

Check whether a given map exists.

public boolean

Returns:

if there are any changes
hasUnsavedChanges
()

Check whether there are any unsaved changes.

public boolean

Returns:

true if store is open, false otherwise
isClosed
()

Determine that store is open, or wait for it to be closed (by other thread)

private boolean

Returns:

true if all data can be read
isKnownVersion
(long
the version
version
)

Check whether all data can be read from this version.

pack-priv boolean
private boolean
public boolean

Returns:

true if persistent
isPersistent
()

Indicates whether this MVStore is backed by FileStore, and therefore it's data will survive this store closure (but not necessary process termination in case of in-memory store).

public boolean

Returns:

true if it is
isReadOnly
()

Whether the store is read-only.

private boolean
isRegularMap(MVMap<?, ?> map)

public boolean
public boolean

Returns:

true if versions are rolling, false otherwise
isVersioningRequired
()

Indicates whether store versions are rolling.

pack-priv void
private boolean
pack-priv void
onVersionChange(long version)

public static MVStore

Returns:

the store
open
(String
the file name (null for in-memory)
fileName
)

Open a store in exclusive mode.

public <
the key type
K
,
the value type
V
>
MVMap<K, V>

Returns:

the map
openMap
(String
the name of the map
name
)

Open a map with the default settings.

public <
the map type
M extends MVMap<K, V>
,
the key type
K
,
the value type
V
>
M

Returns:

the map
openMap
(String
the name of the map
name
,
MVMap.MapBuilder<M, K, V>
the map builder
builder
)

Open a map with the given builder.

public <
the map type
M extends MVMap<K, V>
,
the key type
K
,
the value type
V
>
M

Returns:

the map
openMap
(int
the map id
id
,
MVMap.MapBuilder<M, K, V>
the map builder
builder
)

Open an existing map with the given builder.

public MVMap<String, String>
public void
public void
pack-priv <
key type
K
,
value type
V
>
Page<K, V>

Returns:

the page
readPage
(MVMap<K, V>
the map
map
,
long
the page position
pos
)

Read a page.

public void
registerUnsavedMemory(int
adjustment
memory
)

Adjust amount of "unsaved memory" meaning amount of RAM occupied by pages not saved yet to the file.

pack-priv void
public MVStore.TxCounter

Returns:

TxCounter to be decremented when operation finishes (transaction closed).
registerVersionUsage
()

Register opened operation (transaction).

public void
removeMap(MVMap<?, ?>
the map to remove
map
)

Remove a map from the current version of the store.

public void
removeMap(String
the map name
name
)

Remove map by name.

public void
renameMap(MVMap<?, ?>
the map
map
,
String
the new name
newName
)

Rename a map.

private boolean
pack-priv void
resetLastMapId(int mapId)

public void
rollback()

Revert to the beginning of the current version, reverting all uncommitted changes.

public void
rollbackTo(long
the version to revert to
version
)

Revert to the beginning of the given version.

private void
public void
setAutoCommitDelay(int
the maximum delay
millis
)

Set the maximum delay in milliseconds to auto-commit changes.

public void
setCacheSize(int
the maximum size in KB
kb
)

Set the maximum memory to be used by the cache.

pack-priv void
setCurrentVersion(long curVersion)

private void
setOldestVersionToKeep(long version)

public void
public void
setRetentionTime(int
how many milliseconds to retain old chunks (0 to overwrite them as early as possible)
ms
)

How long to retain old, persisted chunks, in milliseconds.

public void
setReuseSpace(boolean
the new value
reuseSpace
)

Whether empty space in the file should be re-used.

public void
setStoreVersion(int
the new store version
version
)

Update the store version.

public void
setVersionsToKeep(int
the number of versions to keep
count
)

How many versions to retain for in-memory stores.

private void
setWriteVersion(long version)

private long
store(boolean syncWrite)

pack-priv void
private void
storeNow(boolean syncWrite)

public void
sync()

Force all stored changes to be written to the storage.

public long

Returns:

the new version (incremented if there were changes) or -1 if there were no commit
tryCommit
()

Unlike regular commit this method returns immediately if there is commit in progress on another thread, otherwise it acts as regular commit.

private long
pack-priv <R> R
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait