Skip to content

Commit 105c8fc

Browse files
committed
Simplified FS code
1 parent ac72c4e commit 105c8fc

File tree

3 files changed

+80
-31
lines changed

3 files changed

+80
-31
lines changed

s4mount.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,15 @@
2626
import sys
2727

2828
from argparse import ArgumentParser
29-
import logging
3029
import singlestoredb as s2
3130

32-
3331
try:
3432
import faulthandler
3533
except ImportError:
3634
pass
3735
else:
3836
faulthandler.enable()
3937

40-
log = logging.getLogger(__name__)
41-
42-
# def init_logging(debug=False):
43-
# formatter = logging.Formatter('%(asctime)s.%(msecs)03d %(threadName)s: '
44-
# '[%(name)s] %(message)s', datefmt="%Y-%m-%d %H:%M:%S")
45-
# handler = logging.StreamHandler()
46-
# handler.setFormatter(formatter)
47-
# root_logger = logging.getLogger()
48-
# if debug:
49-
# handler.setLevel(logging.DEBUG)
50-
# root_logger.setLevel(logging.DEBUG)
51-
# else:
52-
# handler.setLevel(logging.INFO)
53-
# root_logger.setLevel(logging.INFO)
54-
# root_logger.addHandler(handler)
55-
5638
def daemonize() -> None:
5739
devnull = os.open(os.devnull, os.O_RDWR)
5840
os.dup2(devnull, sys.stdin.fileno())
@@ -68,12 +50,6 @@ def parse_args():
6850
help='Where to mount the file system')
6951
return parser.parse_args()
7052

71-
def mountStage(access_token, base_url, workspaceGroupID, mountpoint):
72-
os.makedirs(f"{mountpoint}/stage/{workspaceGroupID}", exist_ok=True)
73-
workspaceManager = s2.manage_workspaces(access_token, base_url=base_url)
74-
wg = workspaceManager.get_workspace_group(workspaceGroupID)
75-
wg.stage.mount(f"{mountpoint}/stage/{workspaceGroupID}")
76-
7753
def main():
7854
options = parse_args()
7955

singlestoredb/management/files.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ def isDir(self):
390390
def isFile(self):
391391
return not self.isDir()
392392

393-
def children(self):
393+
@property
394+
def children(self) -> List[int]:
394395
if self._children is None:
395396
self._children = []
396397
childrenNames = self.fs.stage.listdir(self.getStagePath())
@@ -400,6 +401,10 @@ def children(self):
400401
self._children.append(childInode.id)
401402

402403
return self._children
404+
405+
def unlink(self, id):
406+
assert self._children is not None
407+
self._children.remove(id)
403408

404409
class SinglestoreFS(pyfuse3.Operations):
405410
def __init__(self, fileLocation: FileLocation):
@@ -453,7 +458,7 @@ async def lookup(self, parent_id, name, ctx=None):
453458

454459
assert parent_inode.isDir()
455460

456-
for child_id in parent_inode.children():
461+
for child_id in parent_inode.children:
457462
child_inode = self.inodes[child_id]
458463
if child_inode.getNameWithoutTrailingSlash() == name.decode():
459464
return await self.getattr(child_id)
@@ -472,7 +477,7 @@ async def readdir(self, fh, start_id, token):
472477

473478
assert inode.isDir()
474479

475-
children = {child: self.inodes[child] for child in inode.children() if child > start_id}
480+
children = {child: self.inodes[child] for child in inode.children if child > start_id}
476481

477482
for child in children.values():
478483
pyfuse3.readdir_reply(
@@ -519,7 +524,7 @@ async def unlink(self, parent_id, name, ctx):
519524
inode = self.inodes[attr.st_ino]
520525
assert inode.isFile()
521526
self.stage.remove(inode.getStagePath())
522-
parent_inode._children.remove(inode.id)
527+
parent_inode.unlink(inode.id)
523528
del self.inodes[inode.id]
524529
return
525530

@@ -544,7 +549,7 @@ async def rename(self, parent_id, name, newparent_id, newname, ctx):
544549
inode.parent = newparent_inode
545550
inode.name = newname.decode()
546551
newparent_inode._children.append(inode.id)
547-
parent_inode._children.remove(inode.id)
552+
parent_inode.unlink(inode.id)
548553
return
549554

550555
async def rmdir(self, parent_id, name, ctx):
@@ -554,7 +559,7 @@ async def rmdir(self, parent_id, name, ctx):
554559
inode = self.inodes[attr.st_ino]
555560
assert inode.isDir()
556561
self.stage.rmdir(inode.getStagePath())
557-
parent_inode._children.remove(inode.id)
562+
parent_inode.unlink(inode.id)
558563
del self.inodes[inode.id]
559564
return
560565

@@ -686,7 +691,7 @@ def mount(self, mountpoint) -> None:
686691
fs = SinglestoreFS(self)
687692
fuse_options = set(pyfuse3.default_options)
688693
# fuse_options.add('fsname=singlestore_fs')
689-
# fuse_options.add('debug')
694+
fuse_options.add('debug')
690695
pyfuse3.init(fs, mountpoint, fuse_options)
691696

692697
try:

stagemount.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
'''
4+
hello.py - Example file system for pyfuse3.
5+
6+
This program presents a static file system containing a single file.
7+
8+
Copyright © 2015 Nikolaus Rath <Nikolaus.org>
9+
Copyright © 2015 Gerion Entrup.
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a copy of
12+
this software and associated documentation files (the "Software"), to deal in
13+
the Software without restriction, including without limitation the rights to
14+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15+
the Software, and to permit persons to whom the Software is furnished to do so.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
'''
24+
25+
import os
26+
import sys
27+
28+
from argparse import ArgumentParser
29+
import singlestoredb as s2
30+
31+
try:
32+
import faulthandler
33+
except ImportError:
34+
pass
35+
else:
36+
faulthandler.enable()
37+
38+
def parse_args():
39+
'''Parse command line'''
40+
41+
parser = ArgumentParser()
42+
43+
parser.add_argument('mountpoint', type=str,
44+
help='Where to mount the file system')
45+
return parser.parse_args()
46+
47+
def main():
48+
options = parse_args()
49+
50+
access_token = os.getenv("API_KEY")
51+
base_url = os.getenv("API_BASEURL")
52+
workspaceGroupID = os.getenv("WORKSPACEGROUP_ID")
53+
if not access_token:
54+
print("API_KEY not set")
55+
sys.exit(1)
56+
if not base_url:
57+
print("API_BASEURL not set")
58+
sys.exit(1)
59+
if not workspaceGroupID:
60+
print("WORKSPACEGROUP_ID not set")
61+
sys.exit(1)
62+
63+
# Mount stage for each workspace group
64+
wg = s2.manage_workspaces(access_token, base_url=base_url).get_workspace_group(workspaceGroupID)
65+
wg.stage.mount(options.mountpoint)
66+
67+
if __name__ == '__main__':
68+
main()

0 commit comments

Comments
 (0)