2024-02-11 01:44:20 +02:00
|
|
|
package repositories
|
|
|
|
|
2024-02-26 21:03:47 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
2024-02-12 21:38:03 +02:00
|
|
|
|
2024-02-26 21:03:47 +02:00
|
|
|
"github.com/google/uuid"
|
|
|
|
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
|
|
|
"github.com/pikami/cosmium/internal/resourceid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// I have no idea what this is tbh
|
2024-12-18 19:39:57 +02:00
|
|
|
func (r *DataRepository) GetPartitionKeyRanges(databaseId string, collectionId string) ([]repositorymodels.PartitionKeyRange, repositorymodels.RepositoryStatus) {
|
|
|
|
r.storeState.RLock()
|
|
|
|
defer r.storeState.RUnlock()
|
2024-12-08 17:54:58 +02:00
|
|
|
|
2024-02-27 20:08:48 +02:00
|
|
|
databaseRid := databaseId
|
|
|
|
collectionRid := collectionId
|
|
|
|
var timestamp int64 = 0
|
|
|
|
|
2024-12-18 19:39:57 +02:00
|
|
|
if database, ok := r.storeState.Databases[databaseId]; !ok {
|
2024-02-27 20:08:48 +02:00
|
|
|
databaseRid = database.ResourceID
|
2024-02-26 21:03:47 +02:00
|
|
|
}
|
|
|
|
|
2024-12-18 19:39:57 +02:00
|
|
|
if collection, ok := r.storeState.Collections[databaseId][collectionId]; !ok {
|
2024-02-27 20:08:48 +02:00
|
|
|
collectionRid = collection.ResourceID
|
|
|
|
timestamp = collection.TimeStamp
|
2024-02-26 21:03:47 +02:00
|
|
|
}
|
|
|
|
|
2024-02-27 20:08:48 +02:00
|
|
|
pkrResourceId := resourceid.NewCombined(databaseRid, collectionRid, resourceid.New())
|
|
|
|
pkrSelf := fmt.Sprintf("dbs/%s/colls/%s/pkranges/%s/", databaseRid, collectionRid, pkrResourceId)
|
2024-02-26 21:03:47 +02:00
|
|
|
etag := fmt.Sprintf("\"%s\"", uuid.New())
|
|
|
|
|
2024-02-12 21:38:03 +02:00
|
|
|
return []repositorymodels.PartitionKeyRange{
|
2024-02-11 01:44:20 +02:00
|
|
|
{
|
2024-02-26 21:03:47 +02:00
|
|
|
ResourceID: pkrResourceId,
|
2024-02-11 01:44:20 +02:00
|
|
|
ID: "0",
|
2024-02-26 21:03:47 +02:00
|
|
|
Etag: etag,
|
2024-02-11 01:44:20 +02:00
|
|
|
MinInclusive: "",
|
|
|
|
MaxExclusive: "FF",
|
|
|
|
RidPrefix: 0,
|
2024-02-26 21:03:47 +02:00
|
|
|
Self: pkrSelf,
|
2024-02-11 01:44:20 +02:00
|
|
|
ThroughputFraction: 1,
|
|
|
|
Status: "online",
|
|
|
|
Parents: []interface{}{},
|
2024-02-27 20:08:48 +02:00
|
|
|
TimeStamp: timestamp,
|
2024-02-11 01:44:20 +02:00
|
|
|
Lsn: 17,
|
|
|
|
},
|
2024-02-12 21:38:03 +02:00
|
|
|
}, repositorymodels.StatusOk
|
2024-02-11 01:44:20 +02:00
|
|
|
}
|