All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xtdb.watermark.IWatermark.kt Maven / Gradle / Ivy

The newest version!
package xtdb.watermark

import org.apache.arrow.vector.types.pojo.Field
import xtdb.api.TransactionKey
import xtdb.trie.MemoryHashTrie
import xtdb.vector.RelationReader
import java.util.concurrent.atomic.AtomicInteger

interface ILiveTableWatermark : AutoCloseable {
    fun columnField(col: String): Field
    fun columnFields(): Map
    fun liveRelation(): RelationReader
    fun liveTrie(): MemoryHashTrie
}

interface ILiveIndexWatermark : AutoCloseable {
    fun allColumnFields(): Map>
    fun liveTable(tableName: String): ILiveTableWatermark
}

class Watermark(
    @JvmField val txBasis: TransactionKey?,
    @JvmField val liveIndex: ILiveIndexWatermark?,
    @JvmField val schema: Map
) : AutoCloseable {
    private val refCount = AtomicInteger(1)

    fun retain() {
        if (0 == refCount.getAndIncrement()) throw IllegalStateException("watermark closed")
    }

    /**
     * releases a reference to the Watermark.
     * if this was the last reference, close it.
     */
    override fun close() {
        if (0 == refCount.decrementAndGet()) liveIndex?.close()
    }
}

interface IWatermarkSource {
    fun openWatermark(): Watermark
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy