Skip to content

Commit

Permalink
Add server version and parallel upload support check APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Feb 9, 2023
1 parent 46ffd7a commit c352793
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
22 changes: 22 additions & 0 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,3 +990,25 @@ func (fs *FileSystem) getDataObject(path string) (*Entry, error) {
// otherwise, retrieve it and add it to cache
return fs.getDataObjectNoCache(path)
}

// GetServerVersion returns server version info
func (fs *FileSystem) GetServerVersion() (*types.IRODSVersion, error) {
conn, err := fs.session.AcquireConnection()
if err != nil {
return nil, err
}
defer fs.session.ReturnConnection(conn)

return conn.GetVersion(), nil
}

// SupportParallelUpload returns if the server supports parallel upload
func (fs *FileSystem) SupportParallelUpload() bool {
conn, err := fs.session.AcquireConnection()
if err != nil {
return false
}
defer fs.session.ReturnConnection(conn)

return conn.SupportParallUpload()
}
6 changes: 6 additions & 0 deletions irods/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func (conn *IRODSConnection) GetVersion() *types.IRODSVersion {
return conn.serverVersion
}

// SupportParallUpload checks if the server supports parallel upload
// available from 4.2.9
func (conn *IRODSConnection) SupportParallUpload() bool {
return conn.serverVersion.HasHigherVersionThan(4, 2, 9)
}

func (conn *IRODSConnection) requiresCSNegotiation() bool {
return conn.account.ClientServerNegotiation
}
Expand Down
13 changes: 3 additions & 10 deletions irods/fs/data_object_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func CloseDataObjectReplica(conn *connection.IRODSConnection, handle *types.IROD
conn.Lock()
defer conn.Unlock()

if !SupportParallUpload(conn) {
if !conn.SupportParallUpload() {
// serial upload
return fmt.Errorf("does not support close replica in current iRODS Version")
}
Expand Down Expand Up @@ -142,13 +142,6 @@ func UploadDataObject(session *session.IRODSSession, localPath string, irodsPath
return replErr
}

// SupportParallUpload checks if current server supports parallel upload
// available from 4.2.9
func SupportParallUpload(conn *connection.IRODSConnection) bool {
irodsVersion := conn.GetVersion()
return irodsVersion.HasHigherVersionThan(4, 2, 9)
}

// UploadDataObjectParallel put a data object at the local path to the iRODS path in parallel
// Partitions a file into n (taskNum) tasks and uploads in parallel
func UploadDataObjectParallel(session *session.IRODSSession, localPath string, irodsPath string, resource string, taskNum int, replicate bool, callback common.TrackerCallBack) error {
Expand Down Expand Up @@ -180,7 +173,7 @@ func UploadDataObjectParallel(session *session.IRODSSession, localPath string, i
return fmt.Errorf("connection is nil or disconnected")
}

if !SupportParallUpload(conn) {
if !conn.SupportParallUpload() {
// serial upload
return UploadDataObject(session, localPath, irodsPath, resource, replicate, callback)
}
Expand Down Expand Up @@ -380,7 +373,7 @@ func UploadDataObjectParallelInBlockAsync(session *session.IRODSSession, localPa
return outputChan, errChan
}

if !SupportParallUpload(conn) {
if !conn.SupportParallUpload() {
// serial upload
outputChan := make(chan int64, 1)
errChan := make(chan error, 1)
Expand Down
2 changes: 1 addition & 1 deletion test/testcases/fs_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ func testParallelUploadAndDownloadDataObject(t *testing.T) {
conn, err := sess.AcquireConnection()
assert.NoError(t, err)

if !fs.SupportParallUpload(conn) {
if !conn.SupportParallUpload() {
sess.ReturnConnection(conn)
return
}
Expand Down

0 comments on commit c352793

Please sign in to comment.