fixed various problems following split of files into fileblobs

This commit is contained in:
gardners 2012-12-04 16:47:45 +10:30
parent 6dfe654ab0
commit f827c7c1c8
5 changed files with 13 additions and 14 deletions

View File

@ -60,7 +60,7 @@ int overlay_mdp_service_rhizomerequest(overlay_mdp_frame *mdp)
journal, then the newer version is okay to use to service this request.
*/
long long row_id=-1;
if (sqlite_exec_int64(&row_id, "SELECT rowid FROM FILES WHERE id IN (SELECT filehash FROM MANIFESTS WHERE manifests.version=%lld AND manifests.id='%s');",
if (sqlite_exec_int64(&row_id, "SELECT rowid FROM FILEBLOBS WHERE id IN (SELECT filehash FROM MANIFESTS WHERE manifests.version=%lld AND manifests.id='%s');",
read_uint64(&mdp->out.payload[RHIZOME_MANIFEST_ID_BYTES]),
alloca_tohex_bid(&mdp->out.payload[0])) < 1)
{
@ -69,7 +69,7 @@ int overlay_mdp_service_rhizomerequest(overlay_mdp_frame *mdp)
}
sqlite3_blob *blob=NULL;
int ret=sqlite3_blob_open(rhizome_db, "main", "files", "data",
int ret=sqlite3_blob_open(rhizome_db, "main", "fileblobs", "data",
row_id, 0 /* read only */, &blob);
if (ret!=SQLITE_OK)
{

View File

@ -1541,7 +1541,7 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath, const unsign
return 0;
}
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
sqlite3_stmt *statement = sqlite_prepare(&retry, "SELECT id FROM fileblobs WHERE (SELECT 1 FROM files WHERE FILEBLOBS.id = FILES.id AND id = ? AND datavalid != 0)");
sqlite3_stmt *statement = sqlite_prepare(&retry, "SELECT rowid FROM fileblobs WHERE (SELECT 1 FROM files WHERE FILEBLOBS.id = FILES.id AND id = ? AND datavalid != 0)");
if (!statement)
return -1;
int ret = 0;
@ -1553,15 +1553,13 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath, const unsign
int stepcode = sqlite_step_retry(&retry, statement);
if (stepcode != SQLITE_ROW) {
ret = 0; // no files found
} else if (!( sqlite3_column_count(statement) == 3
&& sqlite3_column_type(statement, 0) == SQLITE_TEXT
&& sqlite3_column_type(statement, 1) == SQLITE_INTEGER
&& sqlite3_column_type(statement, 2) == SQLITE_INTEGER
} else if (!( sqlite3_column_count(statement) == 1
&& sqlite3_column_type(statement, 0) == SQLITE_INTEGER
)) {
ret = WHY("Incorrect statement column");
} else {
long long length = sqlite3_column_int64(statement, 2);
int64_t rowid = sqlite3_column_int64(statement, 1);
long long length;
int64_t rowid = sqlite3_column_int64(statement, 0);
sqlite3_blob *blob = NULL;
int code;
do code = sqlite3_blob_open(rhizome_db, "main", "FILEBLOBS", "data", rowid, 0 /* read only */, &blob);
@ -1569,6 +1567,7 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath, const unsign
if (!sqlite_code_ok(code)) {
ret = WHY("Could not open blob for reading");
} else {
length = sqlite3_blob_bytes(blob);
cli_puts("filehash"); cli_delim(":");
cli_puts((const char *)sqlite3_column_text(statement, 0)); cli_delim("\n");
cli_puts("filesize"); cli_delim(":");

View File

@ -971,9 +971,9 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
/* send file contents now */
long long rowid = -1;
sqlite3_blob *blob=NULL;
sqlite_exec_int64(&rowid, "select rowid from files where id='%s';", hash);
sqlite_exec_int64(&rowid, "select rowid from fileblobs where id='%s';", hash);
DEBUGF("Reading from rowid #%lld filehash='%s'",rowid,hash?hash:"(null)");
if (rowid >= 0 && sqlite3_blob_open(rhizome_db, "main", "files", "data",
if (rowid >= 0 && sqlite3_blob_open(rhizome_db, "main", "fileblobs", "data",
rowid, 0, &blob) != SQLITE_OK)
goto closeit;
int i;

View File

@ -1092,7 +1092,7 @@ static int rhizome_fetch_mdp_requestblocks(struct rhizome_fetch_slot *slot)
write_uint32(&mdp.out.payload[RHIZOME_BAR_BYTES+8+8],slot->mdpRXBitmap);
write_uint16(&mdp.out.payload[RHIZOME_BAR_BYTES+8+8+4],slot->mdpRXBlockLength);
if (0)
if (1)
DEBUGF("src sid=%s, dst sid=%s, mdpRXWindowStart=0x%x",
alloca_tohex_sid(mdp.out.src.sid),alloca_tohex_sid(mdp.out.dst.sid),
slot->file_ofs);

View File

@ -541,8 +541,8 @@ int rhizome_server_parse_http_request(rhizome_http_request *r)
// TODO: Check for Range: header and return 206 if returning partial content
str_toupper_inplace(id);
long long rowid = -1;
sqlite_exec_int64(&rowid, "select rowid from files where id='%s';", id);
if (rowid >= 0 && sqlite3_blob_open(rhizome_db, "main", "files", "data", rowid, 0, &r->blob) != SQLITE_OK)
sqlite_exec_int64(&rowid, "select rowid from fileblobs where id='%s';", id);
if (rowid >= 0 && sqlite3_blob_open(rhizome_db, "main", "fileblobs", "data", rowid, 0, &r->blob) != SQLITE_OK)
rowid = -1;
if (rowid == -1) {
rhizome_server_simple_http_response(r, 404, "<html><h1>Payload not found</h1></html>\r\n");