Files
seaweedfs/weed/s3api/lance/markers.go
T
d9eaf85cd7 perf(lance): skip unused _versions lookups (#13371)
* lance: skip unused _versions lookups

Read _versions/ only for include_declared=false, check_declared
or a new-name register: listings now do one lookup per table
instead of two (about 45% faster at 100-500 tables).
A failed _versions lookup no longer hides a table that never needed it.

Adds visibility regression tests, lookup-count tests and a benchmark.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* lance: read the deregistered marker through datasetState

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* lance: trim the dataset-state comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
2026-12-03 23:44:47 -08:00

100 lines
3.2 KiB
Go

package lance
import (
"net/http"
"time"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables"
)
// Marker files the Lance Directory Catalog reads. Writing them beside the
// dataset keeps a client that bypasses this namespace, and lists the storage
// prefix directly, seeing the same table states the catalog reports.
const (
reservedMarker = ".lance-reserved"
deregisteredMarker = ".lance-deregistered"
versionsDir = "_versions"
)
// datasetDir maps a table location onto the filer directory holding it.
func datasetDir(location string) string {
return s3tables.TableDataDirFromMetadataLocation(location)
}
func (s *Server) entryExists(r *http.Request, dir, name string) (bool, error) {
entry, err := s.lookupEntry(r, dir, name)
return entry != nil, err
}
func (s *Server) lookupEntry(r *http.Request, dir, name string) (*filer_pb.Entry, error) {
var found *filer_pb.Entry
err := s.filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
resp, lookupErr := filer_pb.LookupEntry(r.Context(), client, &filer_pb.LookupDirectoryEntryRequest{
Directory: dir,
Name: name,
})
if lookupErr == filer_pb.ErrNotFound {
return nil
}
if lookupErr != nil {
return lookupErr
}
found = resp.Entry
return nil
})
return found, err
}
// writeMarker drops a zero-length marker into the dataset directory. The
// directory has to exist already: a table declared through this namespace has
// one, and a table registered at a location that does not yet exist has no
// storage to mark.
func (s *Server) writeMarker(r *http.Request, location, name string) error {
dir := datasetDir(location)
if dir == "" {
return nil
}
now := time.Now().Unix()
return s.filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
return filer_pb.CreateEntry(r.Context(), client, &filer_pb.CreateEntryRequest{
Directory: dir,
Entry: &filer_pb.Entry{
Name: name,
Attributes: &filer_pb.FuseAttributes{
Mtime: now,
Crtime: now,
FileMode: uint32(0644),
},
},
})
})
}
func (s *Server) removeMarker(r *http.Request, location, name string) error {
dir := datasetDir(location)
if dir == "" {
return nil
}
return s.filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
return filer_pb.DoRemove(r.Context(), client, dir, name, true, false, true, false, nil)
})
}
// datasetState reports the two things the spec asks about a table's storage:
// whether it has been deregistered, and whether it holds data yet. A dataset
// holds data once it has a version manifest, which is how a directory catalog
// decides the same question. _versions/ is read only when checkData is set
// and the table is not deregistered; otherwise hasData is false.
func (s *Server) datasetState(r *http.Request, location string, checkData bool) (deregistered, hasData bool, err error) {
dir := datasetDir(location)
if dir == "" {
return false, false, nil
}
if deregistered, err = s.entryExists(r, dir, deregisteredMarker); err != nil || deregistered || !checkData {
return deregistered, false, err
}
hasData, err = s.entryExists(r, dir, versionsDir)
return false, hasData, err
}