| 220 | Status TableBuilder::status() const { return rep_->status; } |
| 221 | |
| 222 | Status TableBuilder::Finish() { |
| 223 | Rep* r = rep_; |
| 224 | Flush(); |
| 225 | assert(!r->closed); |
| 226 | r->closed = true; |
| 227 | |
| 228 | BlockHandle metaindex_block_handle, index_block_handle; |
| 229 | |
| 230 | // Write metaindex block |
| 231 | if (ok()) { |
| 232 | BlockBuilder meta_index_block(&r->options); |
| 233 | // TODO(postrelease): Add stats and other meta blocks |
| 234 | WriteBlock(&meta_index_block, &metaindex_block_handle); |
| 235 | } |
| 236 | |
| 237 | // Write index block |
| 238 | if (ok()) { |
| 239 | if (r->pending_index_entry) { |
| 240 | FindShortSuccessor(&r->last_key); |
| 241 | string handle_encoding; |
| 242 | r->pending_handle.EncodeTo(&handle_encoding); |
| 243 | r->index_block.Add(r->last_key, StringPiece(handle_encoding)); |
| 244 | r->pending_index_entry = false; |
| 245 | } |
| 246 | WriteBlock(&r->index_block, &index_block_handle); |
| 247 | } |
| 248 | |
| 249 | // Write footer |
| 250 | if (ok()) { |
| 251 | Footer footer; |
| 252 | footer.set_metaindex_handle(metaindex_block_handle); |
| 253 | footer.set_index_handle(index_block_handle); |
| 254 | string footer_encoding; |
| 255 | footer.EncodeTo(&footer_encoding); |
| 256 | r->status = r->file->Append(footer_encoding); |
| 257 | if (r->status.ok()) { |
| 258 | r->offset += footer_encoding.size(); |
| 259 | } |
| 260 | } |
| 261 | return r->status; |
| 262 | } |
| 263 | |
| 264 | void TableBuilder::Abandon() { |
| 265 | Rep* r = rep_; |