Class

curiodb

Node

Related Doc: package curiodb

Permalink

abstract class Node[T] extends PersistentActor with CommandProcessing with ActorLogging

Node is the base actor class that all concrete node types subclass Specifically, there is a concrete Node class for each data type namely: StringNode for strings, HashNode for hashes, etc. There are also some special Node types, such as KeyNode which manages the key space for regular Node actors, and ClientNode which manages a single client connection.

The base class here defines the core features of a Node actor, namely:

Persistence warrants some discussion: we use akka-persistence, but not completely, as event sourcing is not used, and we rely entirely on its snapshotting feature, only ever keeping a single snapshot. This was basically the easiest way to get persistence working. We always store a reference to the last snapshot's meta-data (the lastSnapshot var) so that we can delete old snapshots whenever a new one is saved. As for saving, this is controlled via the config var curiodb.persist-after which is the duration after which a command runs that writes the node's value (described as writable in the commands.conf file). When one of these commands runs, we call save, which will schedule a Persist message back to the node itself. This is based on the assumption that there's no guarantee an actor's recieve and scheduler won't both execute at the exact same time, so we have everything run through receive. The persisting var stores whether persisting has been scheduled, to allow extra save calls to do nothing when persisting has already been scheduled.

Linear Supertypes
ActorLogging, CommandProcessing, PersistentActor, Eventsourced, PersistenceRecovery, PersistenceIdentity, StashFactory, Stash, RequiresMessageQueue[DequeBasedMessageQueueSemantics], UnrestrictedStash, StashSupport, Snapshotter, Actor, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Node
  2. ActorLogging
  3. CommandProcessing
  4. PersistentActor
  5. Eventsourced
  6. PersistenceRecovery
  7. PersistenceIdentity
  8. StashFactory
  9. Stash
  10. RequiresMessageQueue
  11. UnrestrictedStash
  12. StashSupport
  13. Snapshotter
  14. Actor
  15. AnyRef
  16. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Node()

    Permalink

Type Members

  1. type CommandRunner = PartialFunction[String, Any]

    Permalink

    Signature for the partial function CommandRunner that actually handles each command.

    Signature for the partial function CommandRunner that actually handles each command. Every Node must implement the "run" method of this type (this requirement is actually codified in the base Node class). It takes a case statement mapping command names to the code that handles them - typically handled inline, or via a method if more complex. The result will then be sent back to the calling ClientNode, and converted into a Redis response before being sent back to the client socket. One special case is the handler returning Unit, in which case no response is sent back, in which case it's up to the handling code to manually send a response back to the client node. A common example of this is all of the aggregation commands, which need to coordinate with multiple nodes before calculating a response. But the bulk of commands are simple one-liners directly returning a response.

    Definition Classes
    CommandProcessing
  2. type Receive = PartialFunction[Any, Unit]

    Permalink
    Definition Classes
    Actor

Abstract Value Members

  1. abstract def emptyValue: T

    Permalink

    Returns the default value for the type of Node, which subclasses must override.

    Returns the default value for the type of Node, which subclasses must override. Used to set the initial value when a Node is first created, and also in the edge case of resetting a transaction's value if within a transaction, the Node is marked deleted, and then recreated.

  2. abstract def run: CommandRunner

    Permalink

    Abstract definition of each Node actor's CommandRunner that must be implemented.

    Abstract definition of each Node actor's CommandRunner that must be implemented. It's the partial function that matches a Command name to the code that runs it.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def aggregate(props: Props): Unit

    Permalink

    Shortcut for creating Aggregate actors.

    Shortcut for creating Aggregate actors.

    Definition Classes
    CommandProcessing
  5. def args: Seq[String]

    Permalink

    Shortcut to the args of the current command.

    Shortcut to the args of the current command.

    Definition Classes
    CommandProcessing
  6. def aroundPostRestart(reason: Throwable): Unit

    Permalink
    Attributes
    protected[akka]
    Definition Classes
    Eventsourced → Actor
  7. def aroundPostStop(): Unit

    Permalink
    Attributes
    protected[akka]
    Definition Classes
    Eventsourced → Actor
  8. def aroundPreRestart(reason: Throwable, message: Option[Any]): Unit

    Permalink
    Attributes
    protected[akka]
    Definition Classes
    Eventsourced → Actor
  9. def aroundPreStart(): Unit

    Permalink
    Attributes
    protected[akka]
    Definition Classes
    Eventsourced → Actor
  10. def aroundReceive(receive: Receive, message: Any): Unit

    Permalink
    Attributes
    protected[akka]
    Definition Classes
    Eventsourced → Actor
  11. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  12. def beginTransaction(): Any

    Permalink

    Moves the current value into a transaction for the current command's client ID.

    Moves the current value into a transaction for the current command's client ID. This can occur at the start of a transaction (eg _MULTI command), or if the Node actor is created inside a transaction, in which case we use emptyValue, which handles the edge case of a Node existing, going into a transaction, being marked deleted, then being recreated.

  13. def bounds(from: Int, to: Int, size: Int): (Int, Int)

    Permalink

    Utility for handling boundary args that wrap around ends of sequences and count backwards when negative.

    Utility for handling boundary args that wrap around ends of sequences and count backwards when negative.

    Definition Classes
    CommandProcessing
  14. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  15. def cloneValue: T

    Permalink

    Clones the value for use in a new transaction.

    Clones the value for use in a new transaction. Node subclasses that work on mutable values must override, typically by calling value.clone, otherwise we just default to the current value.

  16. def closeTransaction(clientId: String = command.clientId, committing: Boolean = false): Option[T]

    Permalink

    Removes and returns the transaction value.

    Removes and returns the transaction value. Expected to run twice per transaction - once when commitTransaction is called when _EXEC is received, and once when the transaction times out. We also check for the lack of a committed value, which indicates that the actor was created in a transaction

  17. var command: Command

    Permalink

    The current command - normally will be set when a Command arrives via the actor's receive method.

    The current command - normally will be set when a Command arrives via the actor's receive method.

    Definition Classes
    CommandProcessing
  18. val commandTimeout: Int

    Permalink

    Timeout for a single command.

    Timeout for a single command. Used by ClientNode to schedule timeout handlers for commands, and also in ScriptRunner to determine what the timeout for a Lua script should be.

    Definition Classes
    CommandProcessing
  19. def commitTransaction(): Any

    Permalink

    Removes the transaction value and writes it back into the main value.

    Removes the transaction value and writes it back into the main value. This could be called after the transaction has timed out, so we only move the value if we're still in a transaction.

  20. implicit val context: ActorContext

    Permalink
    Definition Classes
    Actor
  21. val debug: Boolean

    Permalink

    Flag that enables detailed command debugging.

    Flag that enables detailed command debugging.

    Definition Classes
    CommandProcessing
  22. def deferAsync[A](event: A)(handler: (A) ⇒ Unit): Unit

    Permalink
    Definition Classes
    Eventsourced
  23. def deleteMessages(toSequenceNr: Long): Unit

    Permalink
    Definition Classes
    Eventsourced
  24. def deleteOldSnapshots(stopping: Boolean = false): Unit

    Permalink

    Deletes old snapshots after a new one is saved.

  25. def deleteSnapshot(sequenceNr: Long): Unit

    Permalink
    Definition Classes
    Snapshotter
  26. def deleteSnapshots(criteria: SnapshotSelectionCriteria): Unit

    Permalink
    Definition Classes
    Snapshotter
  27. def durationSetting(name: String): Int

    Permalink

    Retrieves a duration config setting as milliseconds, and handles the value not being a duration value, so we can do something like set it to "off", in which case we default to 0.

    Retrieves a duration config setting as milliseconds, and handles the value not being a duration value, so we can do something like set it to "off", in which case we default to 0.

    Definition Classes
    CommandProcessing
  28. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  29. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  30. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  31. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  32. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  33. def inTransaction: Boolean

    Permalink

    Checks if the current Command is in a transaction.

  34. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  35. val isolationLevel: String

    Permalink

    Transaction isolation level: "repeatable" reads, read "committed", or read "uncommitted".

  36. def journalPluginId: String

    Permalink
    Definition Classes
    PersistenceIdentity
  37. def lastSequenceNr: Long

    Permalink
    Definition Classes
    Eventsourced
  38. var lastSnapshot: Option[SnapshotMetadata]

    Permalink

    The most recently saved snapshot.

    The most recently saved snapshot. We store it on save and recover, so that we can delete it (and any earlier snapshots) each time we successfully save a new snapshot.

  39. def loadSnapshot(persistenceId: String, criteria: SnapshotSelectionCriteria, toSequenceNr: Long): Unit

    Permalink
    Definition Classes
    Snapshotter
  40. def log: LoggingAdapter

    Permalink
    Definition Classes
    ActorLogging
  41. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  42. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  43. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  44. def numberToString(n: Any): String

    Permalink

    Utility for dropping extraneous zeros from floats when converting to strings, for consistency with Redis' INCRBYFLOAT/HINCRBYFLOAT commands and sorted set scores.

    Utility for dropping extraneous zeros from floats when converting to strings, for consistency with Redis' INCRBYFLOAT/HINCRBYFLOAT commands and sorted set scores.

    Definition Classes
    CommandProcessing
  45. def onPersistFailure(cause: Throwable, event: Any, seqNr: Long): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Eventsourced
  46. def onPersistRejected(cause: Throwable, event: Any, seqNr: Long): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Eventsourced
  47. def onRecoveryFailure(cause: Throwable, event: Option[Any]): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    Eventsourced
  48. def pattern(values: Iterable[String], pattern: String): Iterable[String]

    Permalink

    Utility for glob-style filtering.

    Utility for glob-style filtering.

    Definition Classes
    CommandProcessing
  49. def persist[A](event: A)(handler: (A) ⇒ Unit): Unit

    Permalink
    Definition Classes
    Eventsourced
  50. val persistAfter: Int

    Permalink

    Stores the duration which controls the minimum delay between receiving a command that writes, and persisting the actual value written.

  51. def persistAll[A](events: Seq[A])(handler: (A) ⇒ Unit): Unit

    Permalink
    Definition Classes
    Eventsourced
  52. def persistAllAsync[A](events: Seq[A])(handler: (A) ⇒ Unit): Unit

    Permalink
    Definition Classes
    Eventsourced
  53. def persistAsync[A](event: A)(handler: (A) ⇒ Unit): Unit

    Permalink
    Definition Classes
    Eventsourced
  54. def persistenceId: String

    Permalink
    Definition Classes
    Node → PersistenceIdentity
  55. var persisting: Boolean

    Permalink

    Boolean representing whether we've scheduled an internal Persist message, so that it only occurs once at a time according to the duration configured by the curiodb.persist-after setting.

  56. def postRestart(reason: Throwable): Unit

    Permalink
    Definition Classes
    Actor
    Annotations
    @throws( classOf[java.lang.Exception] )
  57. def postStop(): Unit

    Permalink
    Definition Classes
    UnrestrictedStash → Actor
  58. def preRestart(reason: Throwable, message: Option[Any]): Unit

    Permalink
    Definition Classes
    UnrestrictedStash → Actor
  59. def preStart(): Unit

    Permalink
    Definition Classes
    Actor
    Annotations
    @throws( classOf[java.lang.Exception] )
  60. def randomItem(iterable: Iterable[String]): String

    Permalink

    Utility for selecting a random item.

    Utility for selecting a random item.

    Definition Classes
    CommandProcessing
  61. def receive: Receive

    Permalink
    Definition Classes
    Node → PersistentActor → Actor
  62. def receiveCommand: Receive

    Permalink

    Main Receive handler - deals with starting/stopping/persisting, and receiving Command instances, then running the Node actor's CommandRunner.

    Main Receive handler - deals with starting/stopping/persisting, and receiving Command instances, then running the Node actor's CommandRunner.

    Definition Classes
    Node → Eventsourced
  63. def receiveRecover: Receive

    Permalink

    Restore the Node actor's value on startup.

    Restore the Node actor's value on startup.

    Definition Classes
    Node → Eventsourced
  64. def recovery: Recovery

    Permalink
    Definition Classes
    PersistenceRecovery
  65. def recoveryFinished: Boolean

    Permalink
    Definition Classes
    Eventsourced
  66. def recoveryRunning: Boolean

    Permalink
    Definition Classes
    Eventsourced
  67. def rename(fromValue: Any, toCommand: String): Unit

    Permalink

    Handles the RENAME/RENAMENX commands for all node types.

    Handles the RENAME/RENAMENX commands for all node types. Each Node subclass is responsible for converting its value to something that can be used by the relevant command given - this command is typically implemented (and named) differently per node, and knows how to accept fromValue. Renaming is basically a delete, then create a new node, so we first delete ourselves (via the internal _DEL command), then pass the fromValue arg with the given command to what will be a newly created Node.

  68. def respond(response: Any): Unit

    Permalink

    Sends a Response (usually the result of a command) back to the command's destination (usually a ClientNode sending a Command).

    Sends a Response (usually the result of a command) back to the command's destination (usually a ClientNode sending a Command).

    Definition Classes
    CommandProcessing
  69. def route(input: Seq[Any], client: Option[ActorRef] = None): Unit

    Permalink

    Shortcut route method for sending command input without a constructed Command instance, using the state of the current command (eg: db, clientID).

    Shortcut route method for sending command input without a constructed Command instance, using the state of the current command (eg: db, clientID).

    Definition Classes
    CommandProcessing
  70. def route(command: Command): Unit

    Permalink

    Sends an unrouted Command to one or more KeyNode actors, either by routing by key, or broadcasting to all.

    Sends an unrouted Command to one or more KeyNode actors, either by routing by key, or broadcasting to all.

    Definition Classes
    CommandProcessing
  71. def runForAnyNode: CommandRunner

    Permalink

    Alternate Receive handler for all Node actors - these are internal commands can run for any Node type, and are not validated in any way, nor are they configured in commands.conf.

    Alternate Receive handler for all Node actors - these are internal commands can run for any Node type, and are not validated in any way, nor are they configured in commands.conf. Currently used for transaction begin (_MULTI) and commit (_EXEC).

    When _MULTI is received and a transaction is beginning, we store the current value in the transaction map against the transaction's client ID. Subsequent commands within the transaction will then read from and write to the transaction map, until it's committed via the _EXEC command, at which point we copy the value from the transaction map back to the main value, and remove it from the transaction map.

    The transaction may also timeout which is scheduled when _MULTI is received. If this occurs and then _EXEC is received, we don't send acknowledgement back to the ClientNode, so it can then deal with its own timeout.

  72. def save(): Unit

    Permalink

    As discussed above, saves a snapshot.

    As discussed above, saves a snapshot. If curiodb.persist-after is zero or less (which means every change must cause a snapshot to be saved), then just save a snapshot. Otherwise schedule the internal Persist message to save a snapshot, if none has already been scheduled, according to the value of the persisting var.

  73. def saveSnapshot(snapshot: Any): Unit

    Permalink
    Definition Classes
    Snapshotter
  74. def scan(values: Iterable[String]): Seq[String]

    Permalink

    Utility for scan-style commands, namely SCAN/SSCAN/HSCAN/ZSCAN.

    Utility for scan-style commands, namely SCAN/SSCAN/HSCAN/ZSCAN.

    Definition Classes
    CommandProcessing
  75. implicit final val self: ActorRef

    Permalink
    Definition Classes
    Actor
  76. final def sender(): ActorRef

    Permalink
    Definition Classes
    Actor
  77. def slice[T](value: Seq[T]): Seq[T]

    Permalink

    Utility for slicing sequences, for commands such as SLICE, GETRANGE, LRANGE, etc.

    Utility for slicing sequences, for commands such as SLICE, GETRANGE, LRANGE, etc.

    Definition Classes
    CommandProcessing
  78. def snapshotPluginId: String

    Permalink
    Definition Classes
    PersistenceIdentity
  79. def snapshotSequenceNr: Long

    Permalink
    Definition Classes
    Eventsourced → Snapshotter
  80. def snapshotterId: String

    Permalink
    Definition Classes
    Eventsourced → Snapshotter
  81. def sort(values: Iterable[String]): Any

    Permalink

    Handles the SORT command.

    Handles the SORT command. Defined here since it can be run against multiple Node types, namely ListNode, SetNode and SortedSetNode.

  82. def stash(): Unit

    Permalink
    Definition Classes
    StashSupport
  83. def stop(): Unit

    Permalink

    Stops the actor - we define this shortcut to give subclassing traits the chance to override it and inject extra shutdown behavior that concrete actors need not know about.

    Stops the actor - we define this shortcut to give subclassing traits the chance to override it and inject extra shutdown behavior that concrete actors need not know about. Note we wrap context.stop with Try here since it may be called twice due to transaction timeouts.

    Definition Classes
    CommandProcessing
  84. def supervisorStrategy: SupervisorStrategy

    Permalink
    Definition Classes
    Actor
  85. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  86. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  87. val transactionTimeout: Int

    Permalink

    Stores the duration which controls the amount of time we allow a transaction to exist for.

    Stores the duration which controls the amount of time we allow a transaction to exist for. This ensures that if for some reason the transaction does not complete, it can start handling write commands again.

  88. def unhandled(message: Any): Unit

    Permalink
    Definition Classes
    Eventsourced → Actor
  89. def unstashAll(): Unit

    Permalink
    Definition Classes
    Eventsourced → StashSupport
  90. def value: T

    Permalink

    Value getter according to the configured transaction isolation level:

    Value getter according to the configured transaction isolation level:

    - repeatable: should always return the value of the current transaction - uncommitted: always returns the newest written value, even if uncommitted - committed: always return the commit value, even inside a transaction

    Note that there is no "serializable" level since there is no notion of a range query. You can read more info on isolation levels here: https://en.wikipedia.org/wiki/Isolation_(database_systems)

  91. def value_=(value: T): Unit

    Permalink

    Value setter - writes the current value, either to the main key, or a client ID if in a transaction.

  92. var values: LinkedHashMap[String, T]

    Permalink

    MVCC map of transaction values for the Node mapped to client IDs, including the committed "main" value, which is identified with an empty string as its key.

    MVCC map of transaction values for the Node mapped to client IDs, including the committed "main" value, which is identified with an empty string as its key. LinkedHashMap is used so that we can access the most recently written value when transaction isolation is configued as read-uncommitted.

  93. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  94. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  95. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def persist[A](events: Seq[A])(handler: (A) ⇒ Unit): Unit

    Permalink
    Definition Classes
    Eventsourced
    Annotations
    @deprecated
    Deprecated

    (Since version 2.4) use persistAll instead

  2. def persistAsync[A](events: Seq[A])(handler: (A) ⇒ Unit): Unit

    Permalink
    Definition Classes
    Eventsourced
    Annotations
    @deprecated
    Deprecated

    (Since version 2.4) use persistAllAsync instead

Inherited from ActorLogging

Inherited from CommandProcessing

Inherited from PersistentActor

Inherited from Eventsourced

Inherited from PersistenceRecovery

Inherited from PersistenceIdentity

Inherited from StashFactory

Inherited from Stash

Inherited from RequiresMessageQueue[DequeBasedMessageQueueSemantics]

Inherited from UnrestrictedStash

Inherited from StashSupport

Inherited from Snapshotter

Inherited from Actor

Inherited from AnyRef

Inherited from Any

Ungrouped