-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: Abstract state into common pkg
This PR - Abstract state interface into common pkg - move birdwatcher main.go to cmd pkg following convention Signed-off-by: Congqi Xia <[email protected]>
- Loading branch information
Showing
27 changed files
with
267 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package common | ||
|
||
// ExitState simple exit state. | ||
type ExitState struct { | ||
CmdState | ||
} | ||
|
||
// SetupCommands setups the command. | ||
// also called after each command run to reset flag values. | ||
func (s *ExitState) SetupCommands() {} | ||
|
||
// IsEnding returns true for exit State | ||
func (s *ExitState) IsEnding() bool { return true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/milvus-io/birdwatcher/framework" | ||
) | ||
|
||
const ( | ||
logicalBits = 18 | ||
logicalBitsMask = (1 << logicalBits) - 1 | ||
) | ||
|
||
type ParseTSParam struct { | ||
framework.ParamBase `use:"parse-ts" desc:"parse hybrid timestamp"` | ||
args []string | ||
} | ||
|
||
func (p *ParseTSParam) ParseArgs(args []string) error { | ||
p.args = args | ||
return nil | ||
} | ||
|
||
func (s *CmdState) ParseTSCommand(ctx context.Context, p *ParseTSParam) { | ||
if len(p.args) == 0 { | ||
fmt.Println("no ts provided") | ||
} | ||
|
||
for _, arg := range p.args { | ||
ts, err := strconv.ParseUint(arg, 10, 64) | ||
if err != nil { | ||
fmt.Printf("failed to parse ts from %s, err: %s\n", arg, err.Error()) | ||
continue | ||
} | ||
|
||
t, _ := ParseTS(ts) | ||
fmt.Printf("Parse ts result, ts:%d, time: %v\n", ts, t) | ||
} | ||
} | ||
|
||
func ParseTS(ts uint64) (time.Time, uint64) { | ||
logical := ts & logicalBitsMask | ||
physical := ts >> logicalBits | ||
physicalTime := time.Unix(int64(physical/1000), int64(physical)%1000*time.Millisecond.Nanoseconds()) | ||
return physicalTime, logical | ||
} |
Oops, something went wrong.