mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
fix(client): support 3.5.0 java sdk #23068759
Signed-off-by: chihe <chihe@oppo.com>
This commit is contained in:
parent
c41f9f2041
commit
d7c377e5d3
@ -129,6 +129,7 @@ import (
|
||||
"github.com/cubefs/cubefs/util/errors"
|
||||
"github.com/cubefs/cubefs/util/log"
|
||||
"github.com/cubefs/cubefs/util/stat"
|
||||
sysutil "github.com/cubefs/cubefs/util/sys"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -139,7 +140,10 @@ const (
|
||||
MaxSizePutOnce = int64(1) << 23
|
||||
)
|
||||
|
||||
var gClientManager *clientManager
|
||||
var (
|
||||
gClientManager *clientManager
|
||||
sysOutputFile *os.File
|
||||
)
|
||||
|
||||
var (
|
||||
statusOK = C.int(0)
|
||||
@ -673,6 +677,10 @@ func cfs_close_client(id C.int64_t) {
|
||||
}
|
||||
auditlog.StopAudit()
|
||||
log.LogFlush()
|
||||
if sysOutputFile != nil {
|
||||
sysOutputFile.Sync()
|
||||
sysOutputFile.Close()
|
||||
}
|
||||
}
|
||||
|
||||
//export cfs_chdir
|
||||
@ -1510,6 +1518,20 @@ func (c *client) absPath(path string) string {
|
||||
func (c *client) start() (err error) {
|
||||
masters := strings.Split(c.masterAddr, ",")
|
||||
if c.logDir != "" {
|
||||
outputFilePath := gopath.Join(c.logDir, "output.log")
|
||||
outputFile, err := os.OpenFile(outputFilePath, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0o666)
|
||||
sysOutputFile = outputFile
|
||||
if err != nil {
|
||||
err = errors.NewErrorf("Fatal: failed to open output path - %v", err)
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
syslog.SetOutput(outputFile)
|
||||
if err = sysutil.RedirectFD(int(outputFile.Fd()), int(os.Stderr.Fd())); err != nil {
|
||||
err = errors.NewErrorf("Fatal: failed to redirect fd - %v", err)
|
||||
syslog.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if c.logLevel == "" {
|
||||
c.logLevel = "WARN"
|
||||
}
|
||||
|
||||
@ -6,6 +6,9 @@ import com.sun.jna.Pointer;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CfsMount {
|
||||
// Open flags
|
||||
public static final int O_RDONLY = 0;
|
||||
@ -42,16 +45,36 @@ public class CfsMount {
|
||||
private CfsLibrary libcfs;
|
||||
private long cid; // client id allocated by libcfs library
|
||||
|
||||
private Map<String, String> keyValueMap;
|
||||
|
||||
public CfsMount() {
|
||||
libcfs = (CfsLibrary) Native.load("/libcfs.so", CfsLibrary.class);
|
||||
cid = libcfs.cfs_new_client();
|
||||
// libcfs = (CfsLibrary) Native.load("/libcfs.so", CfsLibrary.class);
|
||||
// cid = libcfs.cfs_new_client();
|
||||
keyValueMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public int setClient(String key, String val) {
|
||||
return libcfs.cfs_set_client(this.cid, key, val);
|
||||
keyValueMap.put(key, val);
|
||||
return 0;
|
||||
// return libcfs.cfs_set_client(this.cid, key, val);
|
||||
}
|
||||
|
||||
public int startClient() {
|
||||
String masterAddr;
|
||||
int ret;
|
||||
masterAddr = keyValueMap.get("masterAddr");
|
||||
System.out.println("masterAddr:" + masterAddr);
|
||||
libcfs = (CfsLibrary) Native.load("/libcfs.so", CfsLibrary.class);
|
||||
System.out.println("load libcfs.so" );
|
||||
cid = libcfs.cfs_new_client();
|
||||
for (Map.Entry<String, String> entry : keyValueMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String val = entry.getValue();
|
||||
ret = libcfs.cfs_set_client(cid, key, val);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return libcfs.cfs_start_client(this.cid);
|
||||
}
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ public class TestCfsClient {
|
||||
CfsMount mnt = new CfsMount();
|
||||
|
||||
mnt.setClient("volName", "ltptest");
|
||||
mnt.setClient("masterAddr", "192.168.0.11:17010,192.168.0.12:17010,192.168.0.13:17010");
|
||||
mnt.setClient("masterAddr", "cfs-starfire-ssd.oppo.local");
|
||||
mnt.setClient("logDir", "/data1/cfsJavaClient/log");
|
||||
mnt.setClient("logLevel", "debug");
|
||||
mnt.setClient("accessKey", "jy624wtKbHUER6ZV");
|
||||
|
||||
@ -327,6 +327,9 @@ var (
|
||||
)
|
||||
|
||||
func RecodCost(api string, costUs int64) {
|
||||
if recoder == nil {
|
||||
return
|
||||
}
|
||||
obLk.RLock()
|
||||
ob := obMap[api]
|
||||
obLk.RUnlock()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user