forked from NVIDIA/aistore
/
owt.go
62 lines (55 loc) · 1.8 KB
/
owt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Package cmn provides common constants, types, and utilities for AIS clients
// and AIStore.
/*
* Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved.
*/
package cmn
import (
"strconv"
"github.com/artashesbalabekyan/aistore/cmn/debug"
)
// Object Write Transaction (OWT) is used to control some of the aspects of creating
// new objects in the cluster.
// In particular, OwtGet* group below simultaneously specifies cold-GET variations
// (that all involve reading from a remote backend) and the associated locking
// (that will always reflect a tradeoff between consistency and parallelism)
type OWT int
const (
OwtPut OWT = iota // PUT
OwtMigrate // migrate or replicate objects within cluster (e.g. global rebalance)
OwtPromote // promote target-accessible files and directories
OwtFinalize // finalize object archives
OwtGetTryLock // if !try-lock(exclusive) { return error }; read from remote; ...
OwtGetLock // lock(exclusive); read from remote; ...
OwtGet // GET (with upgrading read-lock in the local-write path)
OwtGetPrefetchLock // (used for maximum parallelism when prefetching)
)
func (owt *OWT) FromS(s string) {
n, err := strconv.Atoi(s)
debug.AssertNoErr(err)
*owt = OWT(n)
}
func (owt OWT) ToS() (s string) { return strconv.Itoa(int(owt)) }
func (owt OWT) String() (s string) {
switch owt {
case OwtPut:
s = "owt-put"
case OwtMigrate:
s = "owt-migrate"
case OwtPromote:
s = "owt-promote"
case OwtFinalize:
s = "owt-finalize"
case OwtGetTryLock:
s = "owt-get-try-lock"
case OwtGetLock:
s = "owt-get-lock"
case OwtGet:
s = "owt-get"
case OwtGetPrefetchLock:
s = "owt-prefetch-lock"
default:
debug.Assert(false)
}
return
}