mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-20 01:10:44 +00:00
Added support for Badger as an alternative storage backend
This commit is contained in:
53
internal/datastore/badger_datastore/partition_key_ranges.go
Normal file
53
internal/datastore/badger_datastore/partition_key_ranges.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package badgerdatastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pikami/cosmium/internal/datastore"
|
||||
"github.com/pikami/cosmium/internal/resourceid"
|
||||
)
|
||||
|
||||
// I have no idea what this is tbh
|
||||
func (r *BadgerDataStore) GetPartitionKeyRanges(databaseId string, collectionId string) ([]datastore.PartitionKeyRange, datastore.DataStoreStatus) {
|
||||
databaseRid := databaseId
|
||||
collectionRid := collectionId
|
||||
var timestamp int64 = 0
|
||||
|
||||
txn := r.db.NewTransaction(false)
|
||||
defer txn.Discard()
|
||||
|
||||
var database datastore.Database
|
||||
status := getKey(txn, generateDatabaseKey(databaseId), &database)
|
||||
if status != datastore.StatusOk {
|
||||
databaseRid = database.ResourceID
|
||||
}
|
||||
|
||||
var collection datastore.Collection
|
||||
status = getKey(txn, generateCollectionKey(databaseId, collectionId), &collection)
|
||||
if status != datastore.StatusOk {
|
||||
collectionRid = collection.ResourceID
|
||||
timestamp = collection.TimeStamp
|
||||
}
|
||||
|
||||
pkrResourceId := resourceid.NewCombined(collectionRid, resourceid.New(resourceid.ResourceTypePartitionKeyRange))
|
||||
pkrSelf := fmt.Sprintf("dbs/%s/colls/%s/pkranges/%s/", databaseRid, collectionRid, pkrResourceId)
|
||||
etag := fmt.Sprintf("\"%s\"", uuid.New())
|
||||
|
||||
return []datastore.PartitionKeyRange{
|
||||
{
|
||||
ResourceID: pkrResourceId,
|
||||
ID: "0",
|
||||
Etag: etag,
|
||||
MinInclusive: "",
|
||||
MaxExclusive: "FF",
|
||||
RidPrefix: 0,
|
||||
Self: pkrSelf,
|
||||
ThroughputFraction: 1,
|
||||
Status: "online",
|
||||
Parents: []interface{}{},
|
||||
TimeStamp: timestamp,
|
||||
Lsn: 17,
|
||||
},
|
||||
}, datastore.StatusOk
|
||||
}
|
||||
Reference in New Issue
Block a user