2012-06-24 3 views
1

저는 ZODB를 사용하고 있습니다. 'database_1.fs' 파일을 다른 'database_2.fs', 에 복사하려고 했으므로 그 'database_1.fs'의 루트 사전을 열었습니다. 텍스트 파일에이 파일 (pickle.dump)을 열었습니다.ZODB에서 절을 뽑았지만 크기가 작습니다.

그럼 내가 사전 변수에 'database_2.fs'의 루트 사전을 업데이트합니다.

그것은 작동하지만, 왜 'database_1.fs'의 크기가 다른 'database_2.fs'의 크기와 같지 않은지 궁금합니다.

그들은 여전히 ​​서로의 사본입니다.

def openstorage(store):    #opens the database 
    data={} 
    data['file']=filestorage 
    data['db']=DB(data['file']) 
    data['conn']=data['db'].open() 
    data['root']=data['conn'].root() 
    return data 

def getroot(dicty): 
    return dicty['root'] 

def closestorage(dicty):    #close the database after Saving 
    transaction.commit() 
    dicty['file'].close() 
    dicty['db'].close() 
    dicty['conn'].close() 
    transaction.get().abort() 

는 그 내가 할 수있는 작업은 다음과 같습니다 -

import pickle 

loc1='G:\\database_1.fs' 
op1=openstorage(loc1) 
root1=getroot(op1) 

loc2='G:database_2.fs' 
op2=openstorage(loc2) 
root2=getroot(op2) 

>>> len(root1) 
215 
>>> len(root2) 
0 

pickle.dump(root1, open("save.txt", "wb")) 
item=pickle.load(open("save.txt", "rb"))   #now item is a dictionary 

root2.update(item) 

closestorage(op1) 
closestorage(op2) 

#after I open both of the databases 
#I get the same keys in both databases 
#But `database_2.fs` is smaller that `database_2.fs` in size I mean. 

>>> len(root2)==len(root1)==215  #they have the same keys 
True 

참고 :

(1) 지속적인 사전 및 목록은 원래 database_1.fs

(2) 모두 그들에있다 동일한 길이와 동일한 색인을가집니다.

+1

ZODB는 영구 트랜잭션 로그 인 AFAIR을 저장합니다. –

+0

당신은 로그 파일이 여분의 크기를 차지한다는 것을 의미합니까 ?? –

답변

0

Google 검색 후 data.fs에 의해 만들어진 ZODB은 ZODB가 개체 실행 취소 기능과 다중 버전 동시성 제어 기능을 제공 할 수 있도록 개체의 이전 복사본에 대한 정보를 실제로 저장한다는 것을 알았습니다. 그래서 이러한 문제를 해결하기 위해 실제로 pack 메서드를 사용할 수 있습니다. 저장 장치를 포장한다는 것은 사용하지 않는 개체 개정을 삭제한다는 것을 의미합니다.

감사합니다.

+0

'ZODB'가 데이터베이스 파일을 저장하는 방법을 오해 한 것으로 생각한다면 항상 환영합니다. –

관련 문제