Skip to content

Commit

Permalink
Make remove.handler use baton.GetBatonHandler()
Browse files Browse the repository at this point in the history
  • Loading branch information
rk1274 committed Feb 19, 2025
1 parent a4224f3 commit 891de16
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
47 changes: 38 additions & 9 deletions baton/baton.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (
extendoLogLevel = logs.ErrorLevel
workerPoolSizeCollections = 2
numCollClients = workerPoolSizeCollections
numPutMetaClients = 2
numPutRemoveMetaClients = 3
collClientMaxIndex = numCollClients - 1
putClientIndex = collClientMaxIndex + 1
metaClientIndex = putClientIndex + 1
Expand All @@ -72,9 +72,10 @@ type Baton struct {
collCh chan string
collErrCh chan error
collMu sync.Mutex
PutMetaPool *ex.ClientPool
putClient *ex.Client
MetaClient *ex.Client
//PutMetaPool *ex.ClientPool

Check failure on line 75 in baton/baton.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
putClient *ex.Client
MetaClient *ex.Client
removeClient *ex.Client
}

// GetBatonHandler returns a Handler that uses Baton to interact with iRODS. If
Expand Down Expand Up @@ -348,20 +349,48 @@ func (b *Baton) CollectionsDone() error {
close(b.collErrCh)
b.collRunning = false

pool, clientCh, err := b.connect(numPutMetaClients)
return b.createPutRemoveMetaClients()
}

func (b *Baton) createPutRemoveMetaClients() error {
pool, clientCh, err := b.connect(numPutRemoveMetaClients)
if err != nil {
b.collMu.Unlock()

return err
}

b.PutMetaPool = pool
b.putClient = <-clientCh
b.MetaClient = <-clientCh
b.removeClient = <-clientCh

pool.Close()

return nil
}

// TODO

Check failure on line 372 in baton/baton.go

View workflow job for this annotation

GitHub Actions / lint

Comment should end in a period (godot)
func (b *Baton) InitClients() error {
if b.putClient == nil && b.MetaClient == nil && b.removeClient == nil {
return b.createPutRemoveMetaClients()
}

if b.putClient != nil && b.MetaClient != nil && b.removeClient != nil {
return nil
}

return internal.Error{"Clients are not in the same state", ""}
}

func (b *Baton) CloseClients() {
var openClients []*ex.Client

Check failure on line 386 in baton/baton.go

View workflow job for this annotation

GitHub Actions / lint

Consider pre-allocating `openClients` (prealloc)
for _, client := range []*ex.Client{b.removeClient, b.putClient, b.MetaClient} {
openClients = append(openClients, client)
}

b.closeConnections(openClients)
}

// closeConnections closes the given connections, with a timeout, ignoring
// errors.
func (b *Baton) closeConnections(clients []*ex.Client) {
Expand Down Expand Up @@ -523,9 +552,9 @@ func (b *Baton) AddMeta(path string, meta map[string]string) error {

// Cleanup stops our clients and closes our client pool.
func (b *Baton) Cleanup() error {
b.closeConnections(append(b.collClients, b.putClient, b.MetaClient))
b.closeConnections(append(b.collClients, b.putClient, b.removeClient, b.MetaClient))

b.PutMetaPool.Close()
// b.PutMetaPool.Close()

b.collMu.Lock()
defer b.collMu.Unlock()
Expand Down Expand Up @@ -623,5 +652,5 @@ func (b *Baton) QueryMeta(dirToSearch string, meta map[string]string) ([]string,
}

func (b *Baton) AllClientsStopped() bool {
return !b.PutMetaPool.IsOpen() && !b.putClient.IsRunning() && !b.MetaClient.IsRunning() && b.collClients == nil
return !b.putClient.IsRunning() && !b.MetaClient.IsRunning() && b.collClients == nil
}
5 changes: 5 additions & 0 deletions remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ type Handler interface {

// QueryMeta return paths to all objects with given metadata
QueryMeta(dirToSearch string, meta map[string]string) ([]string, error)

// TODO

Check failure on line 59 in remove/remove.go

View workflow job for this annotation

GitHub Actions / lint

remove/remove.go:59: Line contains TODO/BUG/FIXME: "TODO" (godox)
InitClients() error

CloseClients()
}

// RemovePathFromSetInIRODS removes the given path from iRODS if the path is not
Expand Down
8 changes: 8 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,17 @@ func (s *Server) EnableJobSubmission(putCmd, deployment, cwd, queue string, numC
// inside removeQueue from iRODS and data base. This function should be called
// inside a go routine, so the user API request is not locked.
func (s *Server) handleRemoveRequests(reserveGroup string) {

Check failure on line 221 in server/server.go

View workflow job for this annotation

GitHub Actions / lint

Function 'handleRemoveRequests' is too long (31 > 30) (funlen)
err := s.storageHandler.InitClients()
if err != nil {
s.Logger.Printf("Failed to init lients: %s", err.Error())
}

for {
item, removeReq, err := s.reserveRemoveRequest(reserveGroup)
if err != nil {
if s.removeQueue.Stats().Items == 0 {
s.storageHandler.CloseClients()
}
break
}

Expand Down

0 comments on commit 891de16

Please # to comment.