mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
84 lines
2.2 KiB
Go
84 lines
2.2 KiB
Go
package shard
|
|
|
|
import (
|
|
persistencespb "go.temporal.io/server/api/persistence/v1"
|
|
"go.temporal.io/server/common/primitives/timestamp"
|
|
"go.temporal.io/server/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
|
|
}
|