Documentation ¶
Index ¶
Constants ¶
View Source
const ( // TimeEpoch : 2024-2-19 TimeEpoch int64 = 1708300800000 // TimeEnd : 2041-2-19 TimeEnd int64 = 2244844800000 // TimeMillisBits milliseconds since TimeEpoch TimeMillisBits = 39 // WorkerBits worker id: 0-3 WorkerBits = 2 // DatabaseBits database id: 0-1023 DatabaseBits = 10 // TableBits table sharding: 0=none/1=yyyyMM/2=yyyy0WW/3=yyyyMMDD TableBits = 2 // SequenceBits sequence: 0-1023 SequenceBits = 10 TimeNowShift = WorkerBits + DatabaseBits + TableBits + SequenceBits WorkerShift = DatabaseBits + TableBits + SequenceBits DatabaseShift = TableBits + SequenceBits TableShift = SequenceBits MaxSequence int16 = -1 ^ (-1 << SequenceBits) // 1023 MaxTableShard int8 = -1 ^ (-1 << TableBits) MaxDatabaseID int16 = -1 ^ (-1 << DatabaseBits) MaxWorkerID int8 = -1 ^ (-1 << WorkerBits) MaxTimeMillis int64 = -1 ^ (-1 << TimeMillisBits) )
Variables ¶
View Source
var ( ErrDataItemIsBusy = errors.New("sqle: data_item_is_busy") ErrNilDHT = errors.New("sqle: dht_is_nil") )
Functions ¶
func FormatMonth ¶ added in v1.3.0
func FormatWeek ¶ added in v1.3.0
Types ¶
type DHT ¶ added in v1.4.0
DHT distributed hash table
type HashRing ¶ added in v1.4.0
type HashRing struct {
// contains filtered or unexported fields
}
HashRing implement consistent hashing for database sharding with hash key
func NewHR ¶ added in v1.4.0
func NewHR(n int, options ...HashRingOption) *HashRing
NewHR create HashRing with n dbs and virtual nodes
type HashRingOption ¶ added in v1.4.0
type HashRingOption func(r *HashRing)
func WithReplicas ¶ added in v1.4.0
func WithReplicas(nodes ...string) HashRingOption
type ID ¶
type ID struct { Time time.Time Int64 int64 TimeMillis int64 Sequence int16 DatabaseID int16 WorkerID int8 TableRotate TableRotate }
ID shardid info
func (ID) MarshalJSON ¶ added in v1.4.6
MarshalJSON implements the json.Marshaler interface
func (*ID) RotateName ¶
RotateName format time parts as rotated table name suffix
func (*ID) UnmarshalJSON ¶ added in v1.4.6
UnmarshalJSON implements the json.Unmarshaler interface
type Option ¶
type Option func(g *Generator)
func WithDailyRotate ¶ added in v1.2.1
func WithDailyRotate() Option
func WithDatabase ¶
func WithMonthlyRotate ¶ added in v1.2.1
func WithMonthlyRotate() Option
func WithRotate ¶ added in v1.2.1
func WithRotate(ts TableRotate) Option
func WithTimeNow ¶
func WithWeeklyRotate ¶ added in v1.2.1
func WithWeeklyRotate() Option
func WithWorkerID ¶
type TableRotate ¶
type TableRotate int8
TableRotate table rotation option
var ( NoRotate TableRotate = 0 MonthlyRotate TableRotate = 1 WeeklyRotate TableRotate = 2 DailyRotate TableRotate = 3 )
Click to show internal directories.
Click to hide internal directories.