Changeset - 3a359a8a2134
[Not reviewed]
default
0 1 0
Laman - 9 years ago 2016-03-26 12:56:44

optimizing disk access
1 file changed with 19 insertions and 4 deletions:
work.py
19
4
0 comments (0 inline, 0 general)
work.py
Show inline comments
 
@@ -86,7 +86,7 @@ def transferChanges(targetPath):
 
			
 
		# transfer modified sectors and mark them as clean
 
		sectorIds=handle.fetchall()
 
		for (sectorId,) in sectorIds:
 
		'''for (sectorId,) in sectorIds:
 
			path=targetPath / getPath(sectorId)
 
			try: path.parent.mkdir(parents=True)
 
			except FileExistsError: pass
 
@@ -94,16 +94,31 @@ def transferChanges(targetPath):
 
			sf.seek(sectorId)
 
			df.write(sf.read(BLOCK_SIZE))
 
			handle.execute("""update `hashes` set `dirty`=0 where `sector_id`=?""",(sectorId,))
 
			db.commit()
 
			db.commit()'''
 
		sector=sf.read(BLOCK_SIZE)
 
		i=j=0
 
		while sector and j<len(sectorIds):
 
			if i==sectorIds[j][0]:
 
				path=targetPath / getPath(sectorId)
 
				try: path.parent.mkdir(parents=True)
 
				except FileExistsError: pass
 
				df=path.open(mode="wb")
 
				df.write(sector)
 
				handle.execute("""update `hashes` set `dirty`=0 where `sector_id`=?""",(sectorIds[j][0],))
 
				db.commit()
 
				j+=1
 
			i+=1
 
			sector=sf.read(BLOCK_SIZE)
 

	
 
def getPath(index):
 
	nodeIds=[]
 
	k=1
 
	while k<=FILE_COUNT:
 
		nodeIds.append(index//k)
 
		paddedLen=int(math.log10(FILE_COUNT/k))
 
		nodeIds.append("{0:0{1}}",index//k,paddedLen)
 
		k*=FILES_PER_DIR
 
	nodeIds.reverse()
 
	return pathlib.Path(*[str(id) for id in nodeIds])
 
	return pathlib.Path(*[id for id in enumerate(nodeIds)])
 

	
 
action=sys.argv[1]
 
fileName=sys.argv[2]
0 comments (0 inline, 0 general)