int si_nodeopen(sinode *n, sr *r, sischeme *scheme, sspath *path, sdsnapshotnode *sn) { int rc = ss_fileopen(&n->file, path->path); if (ssunlikely(rc == -1)) { sr_malfunction(r->e, "db file '%s' open error: %s", ss_pathof(&n->file.path), strerror(errno)); return -1; } rc = ss_fileseek(&n->file, n->file.size); if (ssunlikely(rc == -1)) { sr_malfunction(r->e, "db file '%s' seek error: %s", ss_pathof(&n->file.path), strerror(errno)); goto error; } int in_memory = 0; if (scheme->storage == SI_SIN_MEMORY) in_memory = 1; rc = si_noderecover(n, r, sn, in_memory); if (ssunlikely(rc == -1)) goto error; if (scheme->mmap) { rc = si_nodemap(n, r); if (ssunlikely(rc == -1)) goto error; } return 0; error: si_nodeclose(n, r, 0); return -1; }
int si_nodeopen(sinode *n, sr *r, sischeme *scheme, sspath *path) { int rc = ss_fileopen(&n->file, path->path); if (ssunlikely(rc == -1)) { sr_malfunction(r->e, "db file '%s' open error: %s", ss_pathof(&n->file.path), strerror(errno)); return -1; } rc = ss_fileseek(&n->file, n->file.size); if (ssunlikely(rc == -1)) { sr_malfunction(r->e, "db file '%s' seek error: %s", ss_pathof(&n->file.path), strerror(errno)); goto error; } rc = si_noderecover(n, r, scheme->in_memory); if (ssunlikely(rc == -1)) goto error; if (scheme->mmap) { rc = si_nodemap(n, r); if (ssunlikely(rc == -1)) goto error; } return 0; error: si_nodeclose(n, r); return -1; }
static inline int si_recoversnapshot(si *i, sr *r, sdsnapshot *s) { /* recovery stages: snapshot (1) ok snapshot.incomplete (2) remove snapshot.incomplete snapshot (3) remove snapshot.incomplete, load snapshot snapshot.incomplete */ /* recover snapshot file (crash recover) */ int snapshot = 0; int snapshot_incomplete = 0; char path[1024]; snprintf(path, sizeof(path), "%s/index", i->scheme->path); snapshot = ss_vfsexists(r->vfs, path); snprintf(path, sizeof(path), "%s/index.incomplete", i->scheme->path); snapshot_incomplete = ss_vfsexists(r->vfs, path); int rc; if (snapshot_incomplete) { rc = ss_vfsunlink(r->vfs, path); if (ssunlikely(rc == -1)) { sr_malfunction(r->e, "index file '%s' unlink error: %s", path, strerror(errno)); return -1; } } if (! snapshot) return 0; /* read snapshot file */ snprintf(path, sizeof(path), "%s/index", i->scheme->path); ssize_t size = ss_vfssize(r->vfs, path); if (ssunlikely(size == -1)) { sr_malfunction(r->e, "index file '%s' read error: %s", path, strerror(errno)); return -1; } rc = ss_bufensure(&s->buf, r->a, size); if (ssunlikely(rc == -1)) return sr_oom_malfunction(r->e); ssfile file; ss_fileinit(&file, r->vfs); rc = ss_fileopen(&file, path); if (ssunlikely(rc == -1)) { sr_malfunction(r->e, "index file '%s' open error: %s", path, strerror(errno)); return -1; } rc = ss_filepread(&file, 0, s->buf.s, size); if (ssunlikely(rc == -1)) { sr_malfunction(r->e, "index file '%s' read error: %s", path, strerror(errno)); ss_fileclose(&file); return -1; } ss_bufadvance(&s->buf, size); ss_fileclose(&file); return 0; }