res = ENOMEM;
goto fail;
}
+ printf("dsik %d files %zd\n", disk->id, count);
for (int i=0;i<count;i++) {
printf(" file %d\n", fids[i]);
goto fail;
res = mdb_cursor_get(cursor, &key, &data, MDB_SET);
- printf("set list by file: %d\n", res);
- while (res == 0) {
- printf(" list: %d @ %d\n", ((struct dblistfile *)data.mv_data)->listid, ((struct dblistfile *)data.mv_data)->seq);
- if (size >= alloc) {
- alloc *= 2;
- list = realloc(list, sizeof(*list) * alloc);
- }
- list[size++] = *(struct dblistfile *)data.mv_data;
-
- res = mdb_cursor_get(cursor, &key, &data, MDB_NEXT_DUP);
- }
- mdb_cursor_close(cursor);
+ if (res == 0) {
+ printf("set list by file: %d\n", res);
+ while (res == 0) {
+ printf(" list: %d @ %d\n", ((struct dblistfile *)data.mv_data)->listid, ((struct dblistfile *)data.mv_data)->seq);
+ if (size >= alloc) {
+ alloc *= 2;
+ list = realloc(list, sizeof(*list) * alloc);
+ }
+ list[size++] = *(struct dblistfile *)data.mv_data;
- if (res = mdb_del(tx, db->list_by_file, &key, NULL))
- goto fail;
+ res = mdb_cursor_get(cursor, &key, &data, MDB_NEXT_DUP);
+ }
+ mdb_cursor_close(cursor);
- printf("list entries: %zd\n", size);
-
- for (int i=0;i<size;i++) {
- struct dbfilelist fdata = {
- .seq = list[i].seq,
- .fileid = f->id
- };
- printf("delete file %d from list %d @ %d\n", fdata.fileid, list[i].listid, fdata.seq);
- key.mv_data = &list[i].listid;
- key.mv_size = sizeof(list[i].listid);
- data.mv_data = &fdata;
- data.mv_size = sizeof(fdata);
- if (res = mdb_del(tx, db->file_by_list, &key, &data))
+ if (res = mdb_del(tx, db->list_by_file, &key, NULL))
goto fail;
+
+ printf("list entries: %zd\n", size);
+
+ for (int i=0;i<size;i++) {
+ struct dbfilelist fdata = {
+ .seq = list[i].seq,
+ .fileid = f->id
+ };
+ printf("delete file %d from list %d @ %d\n", fdata.fileid, list[i].listid, fdata.seq);
+ key.mv_data = &list[i].listid;
+ key.mv_size = sizeof(list[i].listid);
+ data.mv_data = &fdata;
+ data.mv_size = sizeof(fdata);
+ if (res = mdb_del(tx, db->file_by_list, &key, &data))
+ goto fail;
+ }
+ } else if (res == MDB_NOTFOUND) {
+ res = 0;
}
free(list);
}
// create shuffled playlist
// TODO: start from an existing playlist?
-void dbshuffle_init2(dbindex *db) {
+void dbshuffle_init2(dbindex *db, dbid_t diskid) {
dbtxn *tx;
dbscan *scan;
uint32_t fid;
// find all current fids
mdb_txn_begin(db->env, NULL, 0, &tx);
- scan = dbfile_scan_disk(tx, db, -1);
+ scan = dbfile_scan_disk(tx, db, diskid);
while ((fid = dbfile_scan_next(scan)) != ~0) {
if (count >= fids_size) {
fids_size *= 2;
rvalue.seq = seq;
rkey.mv_data = &fid;
- printf(" %d->%d\n", seq, fid);
+ //printf(" %d->%d\n", seq, fid);
if ((res = mdb_put(tx, db->file_by_list, &fkey, &fdata, MDB_NODUPDATA)))
goto fail;
#include "dbindex.h"
-void dbshuffle_init2(dbindex *db);
+void dbshuffle_init2(dbindex *db, dbid_t diskid);
int dbdisk_del_id(dbtxn *txn, dbindex *db, int diskid);
void dbindex_validate(dbindex *db);
}
mkdir(dbdir, 0700);
+ srandom(time(NULL));
dbindex *db = dbindex_open(dbdir);
} else if (strcmp(cmd, "-d") == 0) {
diskid = atoi(argv[++i]);
} else if (strcmp(cmd, "--shuffle") == 0) {
- dbshuffle_init2(db);
+ int did = atoi(argv[++i]);
+
+ dbshuffle_init2(db, did);
} else if (strcmp(cmd, "--file-dump") == 0) {
// dump file info
// dump lists it's in