def unpack(cls, bufferPool, buffer): brepr = cls.binrepr(buffer) values = brepr.unpack_from(buffer) if len(values) == 3: fileId = FileId.unpack(values[1]) filePath = values[2].decode() return cls(bufferPool=bufferPool, fileId=fileId, filePath=filePath, mode="update")
def __init__(self, **kwargs): other = kwargs.get("other", None) if other: self.fromOther(other) else: self.bufferPool = kwargs.get("bufferPool", None) self.dataDir = kwargs.get("dataDir", FileManager.defaultDataDir) self.indexDir = kwargs.get("indexDir", os.path.join(self.dataDir, "index")) self.defaultPageSize = kwargs.get("pageSize", io.DEFAULT_BUFFER_SIZE) if self.bufferPool is None: raise ValueError( "No buffer pool found when initializing a file manager") checkpointFound = os.path.exists( os.path.join(self.dataDir, FileManager.checkpointFile)) restoring = "restore" in kwargs if not os.path.exists(self.dataDir): os.makedirs(self.dataDir) if restoring or not checkpointFound: self.fileClass = kwargs.get("fileClass", FileManager.defaultFileClass) self.fileCounter = kwargs.get("fileCounter", 0) self.relationFiles = kwargs.get("relationFiles", {}) self.fileMap = kwargs.get("fileMap", {}) # self.indexManager = kwargs.get("indexManager", IndexManager(indexDir=self.indexDir)) if restoring: self.relationFiles = dict([(i[0], FileId(i[1])) for i in kwargs["restore"][0]]) for i in kwargs["restore"][1]: fId = FileId(i[0]) fPath = i[1] self.fileMap[fId] = \ self.fileClass(bufferPool=self.bufferPool, fileId=fId, filePath=fPath, mode="update") else: self.restore()
def createRelation(self, relId, schema): if relId not in self.relationFiles: fId = FileId(self.fileCounter) path = os.path.join(self.datadir, str(self.fileCounter) + '.rel') self.fileCounter += 1 self.relationFiles[relId] = fId self.fileMap[fId] = \ self.fileClass(bufferPool=self.bufferPool, \ pageSize=self.pageSize, fileId=fId, filePath=path, mode="create", schema=schema) self.checkpoint()
def makeEmptyPage(self): schema = self.makeSchema() pId = PageId(FileId(1), 100) return pageClass(pageId=pId, buffer=bytes(4096), schema=schema)