void AQMatrix::writeTemporaryTable() { if (this->matrix.empty()) return; uint64_t packet = 0; char filename[1024]; FILE * fd; std::vector<std::map<uint64_t, FILE*> > fds(this->matrix.size()); uint32_t status = 11; uint32_t invalid = 0; uint32_t pos = 0; uint64_t grpIndex = 1; uint64_t size = (*this->matrix.begin()).indexes.size(); for (uint64_t i = 0; i < size; ++i, ++grpIndex) { for (size_t c = 0; c < this->matrix.size(); ++c) { pos = static_cast<uint32_t>(this->matrix[c].indexes[i]); packet = pos / settings->packSize; pos = (pos - 1) % settings->packSize; auto it = fds[c].find(packet); if (it == fds[c].end()) { sprintf(filename, "%s/B001REG%.4luTMP%.4"PRIu64"P%.12"PRIu64".TMP", this->settings->tmpPath.c_str(), this->matrix[c].table_id, this->uid, packet); fd = fopen(filename, "wb"); if (fd == nullptr) { throw aq::generic_error(aq::generic_error::COULD_NOT_OPEN_FILE, "cannot create temporary table file '%s'", filename); } if (!fds[c].insert(std::make_pair(packet, fd)).second) { throw aq::generic_error(aq::generic_error::GENERIC, "MEMORY ERROR"); } fwrite(&status, sizeof(uint32_t), 1, fd); } else { fd = it->second; } fwrite(&invalid, sizeof(uint32_t), 1, fd); fwrite(&pos, sizeof(uint32_t), 1, fd); } } for (size_t c = 0; c < this->matrix.size(); ++c) { for (auto& v : fds[c]) { fclose(v.second); } } // FIXME : generate empty file => this is temporary char tableName[128]; for (auto it = this->matrix.begin(); it != this->matrix.end(); ++it) { Table::Ptr table = this->baseDesc->getTable((*it).table_id); uint64_t n = table->getTotalCount() / this->settings->packSize; for (uint64_t i = 0; i <= n; ++i) { sprintf(filename, "%s/B001REG%.4luTMP%.4"PRIu64"P%.12"PRIu64".TMP", this->settings->tmpPath.c_str(), (*it).table_id, this->uid, i); FILE * fd = fopen(filename, "ab"); fclose(fd); } sprintf(tableName, "B001REG%.4luTMP%.4"PRIu64"P%.12"PRIu64, (*it).table_id, this->uid, n + 1); (*it).tableName = tableName; (*it).baseTableName = table->getName(); } }