<commit_before>package shardakka.keyvalue

import akka.actor.{ Props, ReceiveTimeout }
import akka.persistence.PersistentActor
import com.eaio.uuid.UUID
import com.google.protobuf.ByteString
import shardakka.ShardakkaExtension

trait ValueCommand {
  val uuid: UUID
  val key: String
}

trait ValueQuery {
  val key: String
}

object ValueActor {
  def props(name: String) = Props(classOf[ValueActor], name)
}

final class ValueActor(name: String) extends PersistentActor {

  import ValueCommands._
  import ValueEvents._
  import ValueQueries._

  context.setReceiveTimeout(ShardakkaExtension.CacheTTL)

  override def persistenceId = ShardakkaExtension.KVPersistencePrefix + "_" + name + "_" + self.path.name

  private var value: Option[ByteString] = None

  override def receiveCommand: Receive = {
    case Upsert(uuid, _, newValue) ⇒
      persist(ValueUpdated(newValue)) { e ⇒
        value = Some(newValue)
        sender() ! Ack(uuid)
      }
    case Delete(uuid, _) ⇒
      persist(ValueDeleted()) { e ⇒
        value = None
        sender() ! Ack(uuid)
      }
    case Get(_) ⇒
      sender() ! GetResponse(value)
    case ReceiveTimeout ⇒
      context stop self
  }

  override def receiveRecover: Receive = {
    case ValueUpdated(newValue) ⇒ value = Some(newValue)<commit_msg>fix(server:shardakka): don't persist event if value is already deleted<commit_after>package shardakka.keyvalue

import akka.actor.{ Props, ReceiveTimeout }
import akka.persistence.PersistentActor
import com.eaio.uuid.UUID
import com.google.protobuf.ByteString
import shardakka.ShardakkaExtension

trait ValueCommand {
  val uuid: UUID
  val key: String
}

trait ValueQuery {
  val key: String
}

object ValueActor {
  def props(name: String) = Props(classOf[ValueActor], name)
}

final class ValueActor(name: String) extends PersistentActor {

  import ValueCommands._
  import ValueEvents._
  import ValueQueries._

  context.setReceiveTimeout(ShardakkaExtension.CacheTTL)

  override def persistenceId = ShardakkaExtension.KVPersistencePrefix + "_" + name + "_" + self.path.name

  private var value: Option[ByteString] = None

  override def receiveCommand: Receive = {
    case Upsert(uuid, _, newValue) ⇒
      persist(ValueUpdated(newValue)) { e ⇒
        value = Some(newValue)
        sender() ! Ack(uuid)
      }
    case Delete(uuid, _) ⇒
      if (value.isEmpty) {
        persist(ValueDeleted()) { e ⇒
          value = None
          sender() ! Ack(uuid)
        }
      } else {
        sender() ! Ack(uuid)
      }
    case Get(_) ⇒
      sender() ! GetResponse(value)
    case ReceiveTimeout ⇒
      context stop self
  }

  override def receiveRecover: Receive = {
    case ValueUpdated(newValue) ⇒ value = Some(newValue)
{'fraction_non_alphanumeric': 0.09553440702781844, 'fraction_numerical': 0.0, 'mean_word_length': 3.436688311688312, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '831327', 'n_tokens_mistral': 869, 'n_tokens_neox': 879, 'n_words': 218}