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/errors"
|
||||||
"github.com/cubefs/cubefs/util/log"
|
"github.com/cubefs/cubefs/util/log"
|
||||||
"github.com/cubefs/cubefs/util/stat"
|
"github.com/cubefs/cubefs/util/stat"
|
||||||
|
sysutil "github.com/cubefs/cubefs/util/sys"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -139,7 +140,10 @@ const (
|
|||||||
MaxSizePutOnce = int64(1) << 23
|
MaxSizePutOnce = int64(1) << 23
|
||||||
)
|
)
|
||||||
|
|
||||||
var gClientManager *clientManager
|
var (
|
||||||
|
gClientManager *clientManager
|
||||||
|
sysOutputFile *os.File
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
statusOK = C.int(0)
|
statusOK = C.int(0)
|
||||||
@ -673,6 +677,10 @@ func cfs_close_client(id C.int64_t) {
|
|||||||
}
|
}
|
||||||
auditlog.StopAudit()
|
auditlog.StopAudit()
|
||||||
log.LogFlush()
|
log.LogFlush()
|
||||||
|
if sysOutputFile != nil {
|
||||||
|
sysOutputFile.Sync()
|
||||||
|
sysOutputFile.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//export cfs_chdir
|
//export cfs_chdir
|
||||||
@ -1510,6 +1518,20 @@ func (c *client) absPath(path string) string {
|
|||||||
func (c *client) start() (err error) {
|
func (c *client) start() (err error) {
|
||||||
masters := strings.Split(c.masterAddr, ",")
|
masters := strings.Split(c.masterAddr, ",")
|
||||||
if c.logDir != "" {
|
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 == "" {
|
if c.logLevel == "" {
|
||||||
c.logLevel = "WARN"
|
c.logLevel = "WARN"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,9 @@ import com.sun.jna.Pointer;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class CfsMount {
|
public class CfsMount {
|
||||||
// Open flags
|
// Open flags
|
||||||
public static final int O_RDONLY = 0;
|
public static final int O_RDONLY = 0;
|
||||||
@ -42,16 +45,36 @@ public class CfsMount {
|
|||||||
private CfsLibrary libcfs;
|
private CfsLibrary libcfs;
|
||||||
private long cid; // client id allocated by libcfs library
|
private long cid; // client id allocated by libcfs library
|
||||||
|
|
||||||
|
private Map<String, String> keyValueMap;
|
||||||
|
|
||||||
public CfsMount() {
|
public CfsMount() {
|
||||||
libcfs = (CfsLibrary) Native.load("/libcfs.so", CfsLibrary.class);
|
// libcfs = (CfsLibrary) Native.load("/libcfs.so", CfsLibrary.class);
|
||||||
cid = libcfs.cfs_new_client();
|
// cid = libcfs.cfs_new_client();
|
||||||
|
keyValueMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int setClient(String key, String val) {
|
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() {
|
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);
|
return libcfs.cfs_start_client(this.cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ public class TestCfsClient {
|
|||||||
CfsMount mnt = new CfsMount();
|
CfsMount mnt = new CfsMount();
|
||||||
|
|
||||||
mnt.setClient("volName", "ltptest");
|
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("logDir", "/data1/cfsJavaClient/log");
|
||||||
mnt.setClient("logLevel", "debug");
|
mnt.setClient("logLevel", "debug");
|
||||||
mnt.setClient("accessKey", "jy624wtKbHUER6ZV");
|
mnt.setClient("accessKey", "jy624wtKbHUER6ZV");
|
||||||
|
|||||||
@ -327,6 +327,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func RecodCost(api string, costUs int64) {
|
func RecodCost(api string, costUs int64) {
|
||||||
|
if recoder == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
obLk.RLock()
|
obLk.RLock()
|
||||||
ob := obMap[api]
|
ob := obMap[api]
|
||||||
obLk.RUnlock()
|
obLk.RUnlock()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user