mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* lance: a register of a new name needs a Lance dataset at its location A Lance register of a new name takes any free location in the table's namespace (#12473 refuses one another record holds), so it can claim an empty location, or a dropped table's emptied root, in the catalog's stead. A register of a name without a record now authorizes the create with its location (AuthorizeCreateTable: the permission, the namespace check and the refusal of a claimed location run before anything is read, so a location in another namespace is answered alike whether it holds a dataset or not), then refuses with 400 a location holding no Lance dataset (no _versions/). A name that has a record, readable by the caller or not (deregistered, or without GetTable), keeps the existing path: CreateTable answers for it and bringing it back needs UpdateTable (#12552). Test: TestRegisterNeedsALanceDataset: an empty location 400; a caller who may not create 403; a dropped table's root 400; another namespace's path answers the same with and without a dataset; a written dataset registers (positive control). Red with the dataset check removed, the authorization skipped, or the location left out of the authorization; TestDeregisterAndReregisterNeedUpdateTable is red when the dataset check also runs for a name that has a record. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * lance: a register of a name with a record keeps the CreateTable path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * lance: a register needs _versions to be a directory Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Javier de la Torre <jatorre@carto.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
3.0 KiB
Go
99 lines
3.0 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.
|
|
func (s *Server) datasetState(r *http.Request, location string) (deregistered, hasData bool, err error) {
|
|
dir := datasetDir(location)
|
|
if dir == "" {
|
|
return false, false, nil
|
|
}
|
|
if deregistered, err = s.entryExists(r, dir, deregisteredMarker); err != nil {
|
|
return false, false, err
|
|
}
|
|
hasData, err = s.entryExists(r, dir, versionsDir)
|
|
return deregistered, hasData, err
|
|
}
|