This commit is contained in:
parent
59eaef2ae3
commit
3be012e780
|
@ -38,9 +38,11 @@ func initMetrics(ctx context.Context, name string) (context.Context, func() erro
|
||||||
goversion := ""
|
goversion := ""
|
||||||
pkg := ""
|
pkg := ""
|
||||||
host := ""
|
host := ""
|
||||||
|
version := "0.0.1"
|
||||||
if info, ok := debug.ReadBuildInfo(); ok {
|
if info, ok := debug.ReadBuildInfo(); ok {
|
||||||
goversion = info.GoVersion
|
goversion = info.GoVersion
|
||||||
pkg = info.Path
|
pkg = info.Path
|
||||||
|
version = info.Main.Version
|
||||||
}
|
}
|
||||||
if h, err := os.Hostname(); err == nil {
|
if h, err := os.Hostname(); err == nil {
|
||||||
host = h
|
host = h
|
||||||
|
@ -69,7 +71,7 @@ func initMetrics(ctx context.Context, name string) (context.Context, func() erro
|
||||||
)
|
)
|
||||||
|
|
||||||
meter := provider.Meter(name,
|
meter := provider.Meter(name,
|
||||||
api.WithInstrumentationVersion("0.0.1"),
|
api.WithInstrumentationVersion(version),
|
||||||
api.WithInstrumentationAttributes(
|
api.WithInstrumentationAttributes(
|
||||||
attribute.String("app", name),
|
attribute.String("app", name),
|
||||||
attribute.String("host", host),
|
attribute.String("host", host),
|
||||||
|
|
|
@ -64,12 +64,11 @@ func (w wrapSpan) AddEvent(name string, options ...trace.EventOption) {
|
||||||
cfg := trace.NewEventConfig(options...)
|
cfg := trace.NewEventConfig(options...)
|
||||||
|
|
||||||
attrs := cfg.Attributes()
|
attrs := cfg.Attributes()
|
||||||
args := make([]any, len(attrs)*2)
|
args := make([]any, len(attrs))
|
||||||
|
|
||||||
for i, a := range attrs {
|
for i, a := range attrs {
|
||||||
args[2*i] = a.Key
|
args[i] = slog.Attr{Key: string(a.Key), Value: slog.StringValue(a.Value.AsString())}
|
||||||
args[2*i+1] = a.Value
|
}
|
||||||
}
|
|
||||||
|
|
||||||
slog.Debug(name, args...)
|
slog.Debug(name, args...)
|
||||||
}
|
}
|
||||||
|
|
22
lsm/sst.go
22
lsm/sst.go
|
@ -316,15 +316,24 @@ func (l *logFile) LoadSegment(pos int64) (*segmentBytes, error) {
|
||||||
return &segmentBytes{b, -1}, nil
|
return &segmentBytes{b, -1}, nil
|
||||||
}
|
}
|
||||||
func (l *logFile) Find(needle []byte, first bool) (*entryBytes, bool, error) {
|
func (l *logFile) Find(needle []byte, first bool) (*entryBytes, bool, error) {
|
||||||
var last segmentReader
|
var cur, last segmentReader
|
||||||
|
|
||||||
for _, s := range l.segments {
|
for _, s := range l.segments {
|
||||||
e, err := s.FirstEntry()
|
cur = s
|
||||||
|
e, err := cur.FirstEntry()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
k, _ := e.KeyValue()
|
k, _ := e.KeyValue()
|
||||||
if first && bytes.Compare(k, needle) >= 0 {
|
|
||||||
|
if first && bytes.Equal(k, needle) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if first && bytes.Compare(k, needle) > 0 {
|
||||||
|
e, ok, err := cur.Find(needle, first)
|
||||||
|
if ok || err != nil{
|
||||||
|
return e, ok, err
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if !first && bytes.Compare(k, needle) > 0 {
|
if !first && bytes.Compare(k, needle) > 0 {
|
||||||
|
@ -333,7 +342,12 @@ func (l *logFile) Find(needle []byte, first bool) (*entryBytes, bool, error) {
|
||||||
last = s
|
last = s
|
||||||
}
|
}
|
||||||
|
|
||||||
return last.Find(needle, first)
|
e, ok, err := last.Find(needle, first)
|
||||||
|
if ok || err != nil{
|
||||||
|
return e, ok, err
|
||||||
|
}
|
||||||
|
// if by mistake it was not found in the last.. check the next segment.
|
||||||
|
return cur.Find(needle, first)
|
||||||
}
|
}
|
||||||
func (l *logFile) WriteTo(w io.Writer) (int64, error) {
|
func (l *logFile) WriteTo(w io.Writer) (int64, error) {
|
||||||
return l.rd.WriteTo(w)
|
return l.rd.WriteTo(w)
|
||||||
|
|
|
@ -40,7 +40,7 @@ func TestLargeFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
t.Log(f.Stat())
|
t.Log(f.Stat())
|
||||||
|
|
||||||
tt, ok, err := sf.Find(needle, false)
|
tt, ok, err := sf.Find(needle, true)
|
||||||
is.NoErr(err)
|
is.NoErr(err)
|
||||||
is.True(ok)
|
is.True(ok)
|
||||||
key, val := tt.KeyValue()
|
key, val := tt.KeyValue()
|
||||||
|
@ -183,6 +183,17 @@ func TestFindRange(t *testing.T) {
|
||||||
is.Equal(key, []byte("AB"))
|
is.Equal(key, []byte("AB"))
|
||||||
is.Equal(val, uint64(2))
|
is.Equal(val, uint64(2))
|
||||||
|
|
||||||
|
last, ok, err = sf.Find([]byte("AB"), false)
|
||||||
|
is.NoErr(err)
|
||||||
|
|
||||||
|
key, val = last.KeyValue()
|
||||||
|
t.Log(string(key), val)
|
||||||
|
|
||||||
|
is.True(ok)
|
||||||
|
is.Equal(key, []byte("AB"))
|
||||||
|
is.Equal(val, uint64(4))
|
||||||
|
|
||||||
|
|
||||||
last, ok, err = sf.Find([]byte("AC"), false)
|
last, ok, err = sf.Find([]byte("AC"), false)
|
||||||
is.NoErr(err)
|
is.NoErr(err)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user