mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Full module path rebrand from Temporal to Hanzo Tasks: - go.mod module: github.com/hanzoai/tasks - All internal Go imports updated (1906 files) - cmd/server renamed to cmd/tasksd - Binary name: tasksd (was temporal-server) - Docker images: hanzoai/tasks (was temporalio/server) - README rewritten with Hanzo Tasks branding - LLM.md created with integration notes - Makefile, goreleaser, CI workflows updated - go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos) Fork of Temporal.io (MIT license).
84 lines
2.2 KiB
Go
84 lines
2.2 KiB
Go
package shard
|
|
|
|
import (
|
|
persistencespb "github.com/hanzoai/tasks/api/persistence/v1"
|
|
"github.com/hanzoai/tasks/common/primitives/timestamp"
|
|
"github.com/hanzoai/tasks/service/history/tasks"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
func convertPersistenceAckLevelToTaskKey(
|
|
categoryType tasks.CategoryType,
|
|
ackLevel int64,
|
|
) tasks.Key {
|
|
if categoryType == tasks.CategoryTypeImmediate {
|
|
return tasks.NewImmediateKey(ackLevel)
|
|
}
|
|
return tasks.NewKey(timestamp.UnixOrZeroTime(ackLevel), 0)
|
|
}
|
|
|
|
func convertTaskKeyToPersistenceAckLevel(
|
|
categoryType tasks.CategoryType,
|
|
taskKey tasks.Key,
|
|
) int64 {
|
|
if categoryType == tasks.CategoryTypeImmediate {
|
|
return taskKey.TaskID
|
|
}
|
|
return taskKey.FireTime.UnixNano()
|
|
}
|
|
|
|
func ConvertFromPersistenceTaskKey(
|
|
key *persistencespb.TaskKey,
|
|
) tasks.Key {
|
|
return tasks.NewKey(
|
|
timestamp.TimeValue(key.FireTime),
|
|
key.TaskId,
|
|
)
|
|
}
|
|
|
|
func ConvertToPersistenceTaskKey(
|
|
key tasks.Key,
|
|
) *persistencespb.TaskKey {
|
|
return &persistencespb.TaskKey{
|
|
FireTime: timestamppb.New(key.FireTime),
|
|
TaskId: key.TaskID,
|
|
}
|
|
}
|
|
|
|
// ReplicationReaderIDFromClusterShardID convert from cluster ID & shard ID to reader ID
|
|
// NOTE: cluster metadata guarantee
|
|
// 1. initial failover version <= int32 max
|
|
// 2. failover increment <= int32 max
|
|
// 3. initial failover version == cluster ID
|
|
func ReplicationReaderIDFromClusterShardID(
|
|
clusterID int64,
|
|
shardID int32,
|
|
) int64 {
|
|
return clusterID<<32 + int64(shardID)
|
|
}
|
|
|
|
// ReplicationReaderIDToClusterShardID convert from reader ID to cluster ID & shard ID
|
|
// NOTE: see ReplicationReaderIDFromClusterShardID
|
|
func ReplicationReaderIDToClusterShardID(
|
|
readerID int64,
|
|
) (int64, int32) {
|
|
return readerID >> 32, int32(readerID & 0xffffffff)
|
|
}
|
|
|
|
func getMinTaskKey(
|
|
queueState *persistencespb.QueueState,
|
|
) *tasks.Key {
|
|
var minTaskKey *tasks.Key
|
|
if queueState.ExclusiveReaderHighWatermark != nil {
|
|
taskKey := ConvertFromPersistenceTaskKey(queueState.ExclusiveReaderHighWatermark)
|
|
minTaskKey = &taskKey
|
|
}
|
|
for _, readerState := range queueState.ReaderStates {
|
|
taskKey := ConvertFromPersistenceTaskKey(readerState.Scopes[0].Range.InclusiveMin)
|
|
if minTaskKey == nil || taskKey.CompareTo(*minTaskKey) < 0 {
|
|
minTaskKey = &taskKey
|
|
}
|
|
}
|
|
return minTaskKey
|
|
}
|