コード例 #1
0
def main(options):
    """The main function."""
    store = get_shard_store(options.from_shard_id)

    user_ids = options.user_ids or ""
    if options.action == DUMP:
        get_column_names(store, True)
        for c in COPYINFO:
            table = c[0]
            columns = c[1]['columns']
            select = c[1]['query']
            replacements = dict(columns=columns,
                                userids=user_ids,
                                shard_id=options.to_shard_id)
            sql = "COPY (%s) TO '%s/%s.dat';" % (select % replacements,
                                                 options.path, table)
            print "Dumping %s TO %s/%s.dat" % (table, options.path, table),
            storage_tm.begin()
            execute_sql(store, sql)
            storage_tm.abort()
        return

    if options.action == LOAD:
        get_column_names(store, False)
        shard_store = get_shard_store(options.to_shard_id)
        storage_tm.begin()
        print "Dropping Indexes..."
        for sql in DROP_NO_DUPLICATE_SQL:
            shard_store.execute(sql)
        for sql in CREATE_NO_DUPLICATE_SQL:
            shard_store.execute(sql)
        for sql in DROP_INDEXES_SQL:
            shard_store.execute(sql)
        for c in COPYINFO:
            table = c[0]
            columns = c[1]['columns']
            sql = "COPY %s (%s) FROM '%s/%s.dat';" % (table, columns,
                                                      options.path, table)
            print "Loading %s From %s/%s.dat" % (table, options.path,
                                                 table),
            execute_sql(shard_store, sql)
        user_store = get_user_store()
        user_store.execute(INITUSER % dict(shard_id=options.to_shard_id,
                                           userids=user_ids))
        print "Rebuilding Indexes..."
        for sql in DROP_NO_DUPLICATE_SQL:
            execute_sql(shard_store, sql)
        for sql in CREATE_INDEXES_SQL:
            execute_sql(shard_store, sql)
        storage_tm.commit()
        return

    if options.action == DELETE:
        shard_store = get_shard_store(options.from_shard_id)
        storage_tm.begin()
        print "Deleting user data..."
        for sql in DELETE_SQL:
            execute_sql(shard_store, sql % dict(userids=user_ids))
        storage_tm.commit()
コード例 #2
0
def main(options):
    """The main function."""
    store = get_shard_store(options.from_shard_id)

    user_ids = options.user_ids or ""
    if options.action == DUMP:
        get_column_names(store, True)
        for c in COPYINFO:
            table = c[0]
            columns = c[1]['columns']
            select = c[1]['query']
            replacements = dict(columns=columns,
                                userids=user_ids,
                                shard_id=options.to_shard_id)
            sql = "COPY (%s) TO '%s/%s.dat';" % (select % replacements,
                                                 options.path, table)
            print "Dumping %s TO %s/%s.dat" % (table, options.path, table),
            storage_tm.begin()
            execute_sql(store, sql)
            storage_tm.abort()
        return

    if options.action == LOAD:
        get_column_names(store, False)
        shard_store = get_shard_store(options.to_shard_id)
        storage_tm.begin()
        print "Dropping Indexes..."
        for sql in DROP_NO_DUPLICATE_SQL:
            shard_store.execute(sql)
        for sql in CREATE_NO_DUPLICATE_SQL:
            shard_store.execute(sql)
        for sql in DROP_INDEXES_SQL:
            shard_store.execute(sql)
        for c in COPYINFO:
            table = c[0]
            columns = c[1]['columns']
            sql = "COPY %s (%s) FROM '%s/%s.dat';" % (table, columns,
                                                      options.path, table)
            print "Loading %s From %s/%s.dat" % (table, options.path, table),
            execute_sql(shard_store, sql)
        user_store = get_user_store()
        user_store.execute(
            INITUSER % dict(shard_id=options.to_shard_id, userids=user_ids))
        print "Rebuilding Indexes..."
        for sql in DROP_NO_DUPLICATE_SQL:
            execute_sql(shard_store, sql)
        for sql in CREATE_INDEXES_SQL:
            execute_sql(shard_store, sql)
        storage_tm.commit()
        return

    if options.action == DELETE:
        shard_store = get_shard_store(options.from_shard_id)
        storage_tm.begin()
        print "Deleting user data..."
        for sql in DELETE_SQL:
            execute_sql(shard_store, sql % dict(userids=user_ids))
        storage_tm.commit()
コード例 #3
0
    def create(self, klass, *args, **kwargs):
        """Create and verify all attributes on the object.

        will create the object, set the attributes and then
        commit it to the database. then check to see that the
        attributes match.
        """
        try:
            obj = klass()
            for k, v in kwargs.items():
                setattr(obj, k, v)
            self.sstore.add(obj)
        except Exception, e:
            storage_tm.abort()
            raise e
コード例 #4
0
    def create(self, klass, *args, **kwargs):
        """Create and verify all attributes on the object.

        will create the object, set the attributes and then
        commit it to the database. then check to see that the
        attributes match.
        """
        try:
            obj = klass()
            for k, v in kwargs.items():
                setattr(obj, k, v)
            self.sstore.add(obj)
        except Exception, e:
            storage_tm.abort()
            raise e