()
| 430 | } |
| 431 | |
| 432 | func (b *walBlock) Flush() (err error) { |
| 433 | if b.ids.Len() == 0 { |
| 434 | return nil |
| 435 | } |
| 436 | |
| 437 | b.buffer = nil |
| 438 | |
| 439 | // Flush latest meta first |
| 440 | // This mainly contains the slack-adjusted start/end times |
| 441 | metaBytes, err := json.Marshal(b.BlockMeta()) |
| 442 | if err != nil { |
| 443 | return fmt.Errorf("error marshaling meta json: %w", err) |
| 444 | } |
| 445 | |
| 446 | metaPath := filepath.Join(b.walPath(), backend.MetaName) |
| 447 | err = os.WriteFile(metaPath, metaBytes, 0o600) |
| 448 | if err != nil { |
| 449 | return fmt.Errorf("error writing meta json: %w", err) |
| 450 | } |
| 451 | |
| 452 | // Now flush/close current writer |
| 453 | err = b.writer.Close() |
| 454 | if err != nil { |
| 455 | return fmt.Errorf("error closing writer: %w", err) |
| 456 | } |
| 457 | |
| 458 | info, err := b.file.Stat() |
| 459 | if err != nil { |
| 460 | return fmt.Errorf("error getting info: %w", err) |
| 461 | } |
| 462 | sz := info.Size() |
| 463 | |
| 464 | err = b.file.Close() |
| 465 | if err != nil { |
| 466 | return fmt.Errorf("error closing file: %w", err) |
| 467 | } |
| 468 | |
| 469 | b.writeFlush(newWalBlockFlush(b.file.Name(), b.ids, b.meta.DedicatedColumns)) |
| 470 | b.mtx.Lock() |
| 471 | b.flushedSize += sz |
| 472 | b.unflushedSize = 0 |
| 473 | b.mtx.Unlock() |
| 474 | b.ids = common.NewIDMap[int64](b.ids.Len()) // Recreate new id map with same expected size |
| 475 | |
| 476 | // Open next one |
| 477 | return b.openWriter() |
| 478 | } |
| 479 | |
| 480 | // DataLength returns estimated size of WAL files on disk. Used for |
| 481 | // cutting WAL files by max size. |
nothing calls this directly
no test coverage detected