Skip to content

Commit

Permalink
sdk/python: fix gid behavior on creating new file(hadoop compatible ) (
Browse files Browse the repository at this point in the history
…#5571)

Co-authored-by: Davies Liu <[email protected]>
  • Loading branch information
CodingPoeta and davies authored Jan 17, 2025
1 parent b87967f commit fac5515
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .github/scripts/hypo/fs_sdk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,13 @@ def test_issue_e(self):
state.read(file=v2, mode='r', offset=0, user='root', whence=0, length=4)
state.teardown()

def test_issue_f(self):
state = JuicefsMachine()
folders_0 = state.init_folders()
files_0 = state.create_file(content=b'', file_name='b', parent=folders_0, umask=18, user='root')
state.chown(entry=folders_0, owner='user1', user='root')
state.create_file(content=b'', file_name='a', parent=folders_0, umask=18, user='root')
state.teardown()

if __name__ == '__main__':
unittest.main()
unittest.main()
16 changes: 15 additions & 1 deletion sdk/java/libjfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ var (
userGroupCache = make(map[string]map[string][]string) // name -> (user -> groups)

MaxDeletes = meta.RmrDefaultThreads
caller = CALLER_JAVA
)

const (
CALLER_JAVA = iota
CALLER_PYTHON
)

const (
BEHAVIOR_HADOOP = "Hadoop"
)

const (
Expand Down Expand Up @@ -211,7 +221,9 @@ func jfs_set_logger(cb unsafe.Pointer) {
func (w *wrapper) withPid(pid int64) meta.Context {
// mapping Java Thread ID to global one
ctx := meta.NewContext(w.ctx.Pid()*1000+uint32(pid), w.ctx.Uid(), w.ctx.Gids())
ctx.WithValue(meta.CtxKey("behavior"), "Hadoop")
if caller == CALLER_JAVA {
ctx.WithValue(meta.CtxKey("behavior"), BEHAVIOR_HADOOP)
}
return ctx
}

Expand Down Expand Up @@ -337,6 +349,7 @@ type javaConf struct {
PushAuth string `json:"pushAuth"`
PushLabels string `json:"pushLabels"`
PushGraphite string `json:"pushGraphite"`
Caller int `json:"caller"`
}

func getOrCreate(name, user, group, superuser, supergroup string, f func() *fs.FileSystem) int64 {
Expand Down Expand Up @@ -468,6 +481,7 @@ func jfs_init(cname, jsonConf, user, group, superuser, supergroup *C.char) int64
utils.SetLogLevel(logrus.WarnLevel)
}

caller = jConf.Caller
if jConf.MaxDeletes > 0 {
MaxDeletes = jConf.MaxDeletes
}
Expand Down
1 change: 1 addition & 0 deletions sdk/python/juicefs/juicefs/juicefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def __init__(self, name, meta, *, bucket="", storage_class="", read_only=False,
kwargs["pushAuth"] = push_auth
kwargs["pushLabels"] = push_labels
kwargs["pushGraphite"] = push_graphite
kwargs["caller"] = 1

jsonConf = json.dumps(kwargs)
self.umask = os.umask(0)
Expand Down

0 comments on commit fac5515

Please sign in to comment.