The Artima Developer Community
Sponsored Link

Python Buzz Forum
Repairing MetaKit databases

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Phillip Pearson

Posts: 1083
Nickname: myelin
Registered: Aug, 2003

Phillip Pearson is a Python hacker from New Zealand
Repairing MetaKit databases Posted: Oct 6, 2003 1:50 AM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Phillip Pearson.
Original Post: Repairing MetaKit databases
Feed Title: Second p0st
Feed URL: http://www.myelin.co.nz/post/rss.xml
Feed Description: Tech notes and web hackery from the guy that brought you bzero, Python Community Server, the Blogging Ecosystem and the Internet Topic Exchange
Latest Python Buzz Posts
Latest Python Buzz Posts by Phillip Pearson
Latest Posts From Second p0st

Advertisement
The Python Community Server has been a little unstable over the last few days, and it's reminding me of what happened a year or so ago when the database file got corrupted after a system crash. Basically, the server process suddenly starts using huge quantities of CPU time for no apparent reason. This time, I can just restart it and it goes back to normal, but last time it was hanging completely.

The solution was to take the MetaKit database and dump out all the data, then create another database with the same structure and fill it up with the data. Radio/Frontier calls this 'compacting', and Zope calls it 'packing', I think -- it's not exactly an uncommon thing to do. However, I don't know of any utilities that will pack MetaKit databases.

Does anybody know of such a tool?

Update: Scratch that request, I've done it myself. Wasn't hard - MetaKit lets you just pick up a view and drop it into another database. Great!

import metakit, re

# path to your (possibly broken) settings.dat file:
FN = 'settings.dat'
# where to save the compacted version:
NEW_FN = 'settings_2.dat'

# open the databases
s = metakit.storage(FN, 1)
new_s = metakit.storage(NEW_FN, 1)

# we'll build up a copy of the description string here, just to make
# sure we didn't do anything dumb.

total_desc = []
def process_table(desc):
    "copy a single table between the databases"
    print "copying table:", desc

    global total_desc
    total_desc.append(desc)

    # get the table from the source, and create it on the dest
    src = s.getas(desc)
    dest = new_s.getas(desc)

    # copy all rows
    for row in src:
        dest.append(row)

#########

def main():
    # grab full database description
    desc = s.description()

    # split it up into tables and process them one at a time
    sofar = []
    add = sofar.append
    depth = 0
    for c in desc:
        if c == '[':
            depth += 1
        elif c == ']':
            depth -= 1
        if depth == 0 and c == ',':
            process_table("".join(sofar))
            sofar[:] = []
        else:
            add(c)
    process_table("".join(sofar))

    # all done: make sure we really did process them all
    assert ",".join(total_desc) == desc, "didn't get everything!"

    # and save ...
    new_s.commit()

if __name__ == '__main__':
    main()
    print "done."

Comment

Read: Repairing MetaKit databases

Topic: Post-parsing thoughts Previous Topic   Next Topic Topic: Pybloxsom and Haloscan, now playing nicely together

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use