IndexedFile

class IndexedFile

IndexedFile is a record journal. Records may be added, explicitly committed, and looked up by record number. A single arbitrary metadata section can be attached to an indexed file (and will be replaced by subsequent attachments). Concurrent read access is supported for multiple threads, drivers, and external OS processes. Only one writer is permitted.

The exclusive longTermWriterLock is acquired automatically when performing an add, a commit, or modifying the metadata, if it isn't already owned. If it wasn't owned, a refresh always takes place, ensuring the write is relative to the latest consistent state of the file, which the lock secures against change by other processes. At the end of a commit, the lock is always released, which allows other blocked processes to mutate the file, having automatically refreshed their own content as above.

Author

Todd L Smith

Mark van Gulik

Skatje Myers

Parameters

setupActionIfNew

An optional extension function, whose presence indicates the file should be initialized to a valid state that contains no records. At that point, the extension function will run, and the file will be renamed to the given fileReference.

headerBytes

The unique sequence of bytes that identifies the nature of the data in the file's records.

softCacheSize

The maximum number of data blocks to cache in memory. Memory pressure can remove some of these entries, down to the strongCacheSize

strongCacheSize

The number of recently accessed data blocks that are guaranteed to be kept resident in memory, even under memory pressure.

versionCheck

A function that checks whether the version number found in the existing file and the given version are compatible.

Types

Link copied to clipboard
class ByteArrayOutputStream(size: Int) : ByteArrayOutputStream

ByteArrayOutputStream provides direct (unsafe) access to the backing byte array (without requiring it to be copied).

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun add(    record: ByteArray,     start: Int = 0,     length: Int = record.size): Long

Add a portion of the given record to the indexed file. Do not commit the data.

Link copied to clipboard
fun close()

Close the indexed file. No further API calls are permitted.

Link copied to clipboard
fun commit()

Commit the indexed file. In particular, write out the current master node to the underlying file and force a synchronization of the file's data and metadata buffers to disk.

Link copied to clipboard
operator fun get(index: Long): ByteArray

Answer the requested record.

Link copied to clipboard
fun refresh()

Update the state of the IndexedFile driver from the physical contents of the indexed file.

Link copied to clipboard
open override fun toString(): String

Properties

Link copied to clipboard
var metadata: ByteArray?

The client-provided metadata, as a byte array, or null if no metadata has ever been specified.

Link copied to clipboard
val size: Long

Answer the size of the indexed file, in records.