static rc_t Work(Db* db, SpotIterator* it) { rc_t rc = 0; bool toRedact = false; int64_t row_id = 0; spotid_t nSpots = 0; spotid_t redactedSpots = 0; uint8_t filter[64]; memset(filter, SRA_READ_FILTER_REDACTED, sizeof filter); assert(it); while (rc == 0 && SpotIteratorNext(it, &rc, &row_id, &toRedact)) { uint8_t nreads = 0; char bufferIn[64]; void* buffer = NULL; uint32_t row_len = 0; rc = Quitting(); ++nSpots; if (rc == 0) { uint32_t elem_bits = 8; rc = VCursorReadDirect(db->rCursor, row_id, db->rFilterIdx, elem_bits, bufferIn, sizeof bufferIn, &row_len); DISP_RC(rc, "while reading READ_FILTER"); nreads = row_len; } if (toRedact) { buffer = filter; ++redactedSpots; DBGMSG(DBG_APP,DBG_COND_1, ("Redacting spot %d: %d reads\n",row_id,nreads)); } else { buffer = bufferIn; } if (rc == 0) { rc = VCursorOpenRow(db->wCursor); DISP_RC(rc, "while opening row to write"); if (rc == 0) { rc = VCursorWrite (db->wCursor, db->wIdx, 8 * nreads, buffer, 0, 1); DISP_RC(rc, "while writing READ_FILTER"); } if (rc == 0) { rc = VCursorCommitRow(db->wCursor); DISP_RC(rc, "while committing row"); } if (rc == 0) { rc = VCursorCloseRow(db->wCursor); DISP_RC(rc, "while closing row"); } } } db->nSpots = nSpots; db->redactedSpots = redactedSpots; if (rc == 0) { rc = VCursorCommit(db->wCursor); DISP_RC(rc, "while committing cursor"); } return rc; }
static rc_t SDataUpdate(struct SData* self, const char* newColName, const char* redactFileName, spotid_t* redactedSpots, spotid_t* all) { struct SBlob blob; uint8_t filter[32]; rc_t rc = 0, rc2 = 0; uint32_t colIdx = 0; spotid_t spot = 0, last = 0; bool toRedact = false; struct SpotIterator it; assert(self && redactedSpots && all); memset(filter, SRA_READ_FILTER_REDACTED, sizeof filter); if ((rc = SpotIteratorInit(&it, self->_rdTbl, redactFileName)) == 0) { rc = SRATableOpenColumnWrite (self->_wrTbl, &colIdx, NULL, newColName, sra_read_filter_t); if (rc != 0) { plogerr(klogErr, rc, "cannot open Column $(path) for Write", "path=%s", newColName); return rc; } } else { return rc; } rc = SBlobInit(&blob, self, &it); if (rc != 0) { return rc; } while (rc == 0 && SpotIteratorNext(&it, &rc, &spot, &toRedact)) { bitsz_t offset = 0, size = 0; const void *base = NULL; uint8_t nReads = 0; if (rc != 0) { break; } plogmsg(klogDebug2, "Spot $(spot): $(action)", PLOG_U32(spot) ",action=%s", spot, toRedact ? "redact" : "original"); /* GET NEXT BLOB RANGE */ if (spot == 1 || spot > last) { rc = SBlobGetRange(&blob, spot, &last); if (rc != 0) { break; } } assert(spot <= last); /* GET NREADS */ if ((rc = SRAColumnRead (self->_NReadsCol, spot, &base, &offset, &size)) != 0) { logerr(klogErr, rc, "cannot SRAColumnRead"); break; } else if (offset != 0 || size != sizeof nReads * 8) { rc = RC(rcExe, rcColumn, rcReading, rcData, rcInvalid); plogerr(klogErr, rc, "Bad SRAColumnRead(\"NREADS\", $(spot)) result", PLOG_U32(spot), spot); } else { nReads = *((uint8_t*) base); if (spot == 1) { if (nReads == 1) { plogmsg(klogInfo, "The first spot has $(nreads) read", "nreads=%d", nReads); } else { plogmsg(klogInfo, "The first spot has $(nreads) reads", "nreads=%d", nReads); } } } /* GET READ_FILTER */ if (toRedact) { base = filter; ++(*redactedSpots); } else { if ((rc = SRAColumnRead(self->_origFilterCol, spot, &base, &offset, &size)) != 0) { plogerr(klogErr, rc, "while calling SRAColumnRead($(name))", "name=%s", "READ_FILTER"); break; } else if (offset != 0 || size != sizeof (uint8_t) * 8 * nReads) { rc = RC(rcExe, rcColumn, rcReading, rcData, rcInvalid); plogerr(klogErr, rc, "Bad SRAColumnRead($(spot)) result", PLOG_U32(spot), spot); } } if ((rc = SRATableOpenSpot(self->_wrTbl, spot)) != 0) { plogerr(klogErr, rc, "cannot open Spot $(id)", PLOG_U32(id), spot); break; } if ((rc = SRATableWriteIdxColumn(self->_wrTbl, colIdx, base, 0, sizeof (uint8_t) * 8 * nReads)) != 0) { logerr(klogErr, rc, "cannot SRATableWriteIdxColumn"); break; } if ((rc = SRATableCloseSpot(self->_wrTbl)) != 0) { logerr(klogErr, rc, "cannot SRATableCloseSpot"); break; } /* CUT THE BLOB */ if (spot == last) { rc = SRATableCloseCursor(self->_wrTbl); if (rc != 0) { plogerr(klogErr, rc, "cannot SRATableCloseCursor $(id)", PLOG_U32(id), spot); break; } } } rc2 = SpotIteratorDestroy(&it); if (rc == 0) { rc = rc2; } *all = spot; return rc; }