Skip to content

Commit

Permalink
Pack UUID bits and seqNr into base64 string
Browse files Browse the repository at this point in the history
  • Loading branch information
leviramsey committed Nov 10, 2024
1 parent 18aec0a commit 2bc0c00
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

package akka.persistence.dynamodb.internal

import java.nio.ByteBuffer
import java.time.Instant
import java.util.concurrent.CompletionException
import java.util.Base64
import java.util.{ HashMap => JHashMap }
import java.util.UUID

import scala.concurrent.ExecutionContext
import scala.concurrent.Future
Expand Down Expand Up @@ -39,6 +42,7 @@ import software.amazon.awssdk.services.dynamodb.model.Update
@InternalApi private[akka] object JournalDao {
private val log: Logger = LoggerFactory.getLogger(classOf[JournalDao])

private val base64Encoder = Base64.getEncoder
}

/**
Expand Down Expand Up @@ -124,13 +128,17 @@ import software.amazon.awssdk.services.dynamodb.model.Update
.build()
}.asJava

val firstEvent = events.head;
val token = {
val base = s"${firstEvent.writerUuid}-${firstEvent.seqNr.toString}"
val len = base.length
if (len > 36) {
base.substring(len - 36, len)
} else base
val firstEvent = events.head
val uuid = UUID.fromString(firstEvent.writerUuid)
val seqNr = firstEvent.seqNr
val bb = ByteBuffer.allocate(24)
bb.asLongBuffer()
.put(uuid.getMostSignificantBits)
.put(uuid.getLeastSignificantBits)
.put(seqNr)

new String(base64Encoder.encode(bb.array))
}

val req = TransactWriteItemsRequest
Expand Down

0 comments on commit 2bc0c00

Please sign in to comment.