Skip to content

Commit

Permalink
page now has their pid assigned to resolve racing conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratchet committed Jan 30, 2024
1 parent c05d703 commit 4ad3486
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tablite/_nimlite/funcs/column_selector/collectinfo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ proc collectColumnSelectInfo*(table: nimpy.PyObject, cols: nimpy.PyObject, dirPi

var isCorrectType = initTable[string, bool]()

proc genpage(dirpid: string): ColSliceInfo {.inline.} = (dir_pid, tabliteBase().SimplePage.next_id(dir_pid).to(int))
proc genpage(dirpid: string): ColSliceInfo {.inline.} = (dir_pid, tabliteBase().SimplePage.next_id(dir_pid).to(string))

discard pbar.update(5)
discard pbar.display()
Expand Down
2 changes: 1 addition & 1 deletion tablite/_nimlite/funcs/column_selector/infos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from std/sugar import collect
from ../../pymodules import builtins
from ../../pytypes import KindObjectND, str2ObjKind

type ColSliceInfo* = (string, int)
type ColSliceInfo* = (string, string)
type ColInfo* = Table[string, ColSliceInfo]
type DesiredColumnInfo* = object
originalName*: string
Expand Down
2 changes: 1 addition & 1 deletion tablite/_nimlite/funcs/column_selector/sliceconv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ proc finalizeSlice(indices: var seq[int], columnNames: seq[string], infos: var T

proc toColSliceInfo(path: Path): ColSliceInfo =
let workdir = string path.parentDir.parentDir
let pid = parseInt(string path.extractFilename.changeFileExt(""))
let pid = string path.extractFilename.changeFileExt("")

return (workdir, pid)

Expand Down
2 changes: 1 addition & 1 deletion tablite/_nimlite/funcs/text_reader/text_reader.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ proc textReaderTask*(task: TaskArgs): seq[nimpy.PyObject] =
for i in 0..<n_pages:
let path = Path(destinations[i])
let workdir = string path.parentDir.parentDir
let id = parseInt(string path.extractFilename.changeFileExt(""))
let id = string path.extractFilename.changeFileExt("")
let dtypes = pgTypes[i]
let len = pgLens[i]

Expand Down
2 changes: 1 addition & 1 deletion tablite/_nimlite/numpy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ proc type2PyType(`type`: KindObjectND): nimpy.PyObject =
of K_TIME: return pymodules.datetime().time
of K_DATETIME: return pymodules.datetime().datetime

proc newPyPage*(id: int, path: string, len: int, dtypes: Table[KindObjectND, int]): nimpy.PyObject =
proc newPyPage*(id: string, path: string, len: int, dtypes: Table[KindObjectND, int]): nimpy.PyObject =
let pyDtypes = pymodules.builtins().dict()

for (dt, n) in dtypes.pairs:
Expand Down
5 changes: 2 additions & 3 deletions tablite/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class SimplePage(object):
autocleanup = True

def __init__(self, id, path, len, py_dtype) -> None:
self.id = id
self.path = Path(path) / "pages" / f"{id}.npy"
self.len = len
self.dtype = py_dtype
Expand All @@ -97,7 +96,7 @@ def next_id(cls, path):
path = Path(path)

while True:
_id = next(cls.ids)
_id = f"{os.getpid()}-{next(cls.ids)}"
_path = path / "pages" / f"{_id}.npy"

if not _path.exists():
Expand All @@ -117,7 +116,7 @@ def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.path}, <{e}>)"

def __hash__(self) -> int:
return hash(self.id)
return hash(self.path)

def owns(self):
parts = self.path.parts
Expand Down
3 changes: 3 additions & 0 deletions tablite/joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,11 @@ def _mp_reindex_page(
if np.any(mask):
nones = np.full(ix_arr.shape, fill_value=None)
array = np.where(mask, nones, array)


Constr = type(T)
remapped_T = Constr({column_name: array}, _path=path)

return remapped_T


Expand Down

0 comments on commit 4ad3486

Please sign in to comment.