-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add decode kvsdb tool #2059
Merged
Merged
add decode kvsdb tool #2059
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70bc042
add decode kvsdb tool
datelier 7882c01
style: Format code with prettier and gofumpt
deepsource-autofix[bot] 472e20a
add csv header
datelier c3ddfba
modify to strings.Builder
datelier 71c0327
style: Format code with prettier and gofumpt
deepsource-autofix[bot] 7972aa4
modify to encoding/csv
datelier 5e12307
add error check
datelier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,91 @@ | ||||||||||
// | ||||||||||
// Copyright (C) 2019-2023 vdaas.org vald team <[email protected]> | ||||||||||
// | ||||||||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
// you may not use this file except in compliance with the License. | ||||||||||
// You may obtain a copy of the License at | ||||||||||
// | ||||||||||
// https://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
// | ||||||||||
// Unless required by applicable law or agreed to in writing, software | ||||||||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
// See the License for the specific language governing permissions and | ||||||||||
// limitations under the License. | ||||||||||
// | ||||||||||
|
||||||||||
package main | ||||||||||
|
||||||||||
import ( | ||||||||||
"encoding/csv" | ||||||||||
"encoding/gob" | ||||||||||
"flag" | ||||||||||
"io/fs" | ||||||||||
"os" | ||||||||||
"strconv" | ||||||||||
"unsafe" | ||||||||||
|
||||||||||
"github.com/vdaas/vald/internal/file" | ||||||||||
"github.com/vdaas/vald/internal/log" | ||||||||||
) | ||||||||||
|
||||||||||
var ( | ||||||||||
format = flag.String("format", "csv", "file format(csv,tsv)") | ||||||||||
kvsFileName = flag.String("file", "ngt-meta.kvsdb", "kvsdb file name") | ||||||||||
kvsTimestampFileName = flag.String("timestamp-file", "ngt-timestamp.kvsdb", "kvsdb timestamp file name") | ||||||||||
path = flag.String("path", ".", "kvsdb file path") | ||||||||||
) | ||||||||||
|
||||||||||
func main() { | ||||||||||
flag.Parse() | ||||||||||
log.Init() | ||||||||||
|
||||||||||
// value | ||||||||||
m := make(map[string]uint32) | ||||||||||
gob.Register(map[string]uint32{}) | ||||||||||
var f *os.File | ||||||||||
defer f.Close() | ||||||||||
f, _ = file.Open( | ||||||||||
file.Join(*path, *kvsFileName), | ||||||||||
os.O_RDONLY|os.O_SYNC, | ||||||||||
fs.ModePerm, | ||||||||||
) | ||||||||||
_ = gob.NewDecoder(f).Decode(&m) | ||||||||||
|
||||||||||
// timestamp | ||||||||||
mt := make(map[string]int64) | ||||||||||
gob.Register(map[string]int64{}) | ||||||||||
var ft *os.File | ||||||||||
defer ft.Close() | ||||||||||
ft, _ = file.Open( | ||||||||||
file.Join(*path, *kvsTimestampFileName), | ||||||||||
os.O_RDONLY|os.O_SYNC, | ||||||||||
fs.ModePerm, | ||||||||||
) | ||||||||||
_ = gob.NewDecoder(ft).Decode(&mt) | ||||||||||
|
||||||||||
var s [][]string | ||||||||||
w := csv.NewWriter(os.Stdout) | ||||||||||
defer w.Flush() | ||||||||||
switch *format { | ||||||||||
case "csv": | ||||||||||
case "tsv": | ||||||||||
w.Comma = '\t' | ||||||||||
default: | ||||||||||
w.Comma = ' ' | ||||||||||
} | ||||||||||
s = append(s, []string{"uuid", "oid", "timestamp"}) | ||||||||||
for k, id := range m { | ||||||||||
if ts, ok := mt[k]; ok { | ||||||||||
s = append(s, []string{k, strconv.FormatUint(uint64(id), 10), strconv.FormatInt(ts, 10)}) | ||||||||||
} else { | ||||||||||
s = append(s, []string{k, strconv.FormatUint(uint64(id), 10), "0"}) | ||||||||||
} | ||||||||||
if len(s)*int(unsafe.Sizeof("")) > 4e+6 { | ||||||||||
w.WriteAll(s) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above
Suggested change
|
||||||||||
s = nil | ||||||||||
} | ||||||||||
} | ||||||||||
w.WriteAll(s) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above
Suggested change
|
||||||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should stop this program like below when it returns errors because there can be the case such as no permission.
And I think you should consider logging levels.
This suggestion is just idea.