ReadPageAndHWMSize reads Page size and HWM (id of the last+1 Page). This is not transactionally safe.
(path string)
| 91 | // ReadPageAndHWMSize reads Page size and HWM (id of the last+1 Page). |
| 92 | // This is not transactionally safe. |
| 93 | func ReadPageAndHWMSize(path string) (uint64, common.Pgid, error) { |
| 94 | // Open database file. |
| 95 | f, err := os.Open(path) |
| 96 | if err != nil { |
| 97 | return 0, 0, err |
| 98 | } |
| 99 | defer f.Close() |
| 100 | |
| 101 | // Read 4KB chunk. |
| 102 | buf := make([]byte, 4096) |
| 103 | if _, err := io.ReadFull(f, buf); err != nil { |
| 104 | return 0, 0, err |
| 105 | } |
| 106 | |
| 107 | // Read Page size from metadata. |
| 108 | m := common.LoadPageMeta(buf) |
| 109 | if m.Magic() != common.Magic { |
| 110 | return 0, 0, fmt.Errorf("the Meta Page has wrong (unexpected) magic") |
| 111 | } |
| 112 | return uint64(m.PageSize()), common.Pgid(m.Pgid()), nil |
| 113 | } |
| 114 | |
| 115 | // GetRootPage returns the root-page (according to the most recent transaction). |
| 116 | func GetRootPage(path string) (root common.Pgid, activeMeta common.Pgid, err error) { |
no test coverage detected