Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MDB) distinguish between recoverable and non-recoverable errors #3

Open
chuigda opened this issue Feb 8, 2020 · 0 comments
Open
Assignees
Labels
30RMB Fix this issue to win 30 RMB!

Comments

@chuigda
Copy link
Member

chuigda commented Feb 8, 2020

As is known before, there're two kinds of errors:

  strcpy(pathbuf, options.db_name);
  strcat(pathbuf, ".db.super");
  db->fp_superblock = fopen(pathbuf, "w");
  if (db->fp_superblock == NULL) {
    mdb_free(db);
    return mdb_status(MDB_ERR_OPEN_FILE,
                      "cannot open superblock file as write");
  }

The error above is recoverable. If one cannot fopen a database super file as write, there is exactly no loss. However, the following error, is non-recoverable

    mdb_ptr_t index_ptr;
    mdb_status_t index_alloc_status = mdb_index_alloc(db, &index_ptr);
    STAT_CHECK_RET(index_alloc_status, {;});
    mdb_ptr_t value_ptr;
    mdb_status_t data_alloc_status = mdb_data_alloc(db, value_size, &value_ptr);
    STAT_CHECK_RET(data_alloc_status, {
                     (void)mdb_index_free(db, index_ptr);
                   });
    mdb_status_t data_write_status = mdb_write_data(db, value_ptr, value,
                                                    value_size);
    STAT_CHECK_RET(data_write_status, {
                     (void)mdb_data_free(db, value_ptr, value_size);
                     (void)mdb_index_free(db, index_ptr);
                   });
    mdb_status_t index_write_status = mdb_write_index(db, index_ptr, key,
                                                      value_ptr, value_size);
    STAT_CHECK_RET(index_write_status, {
                     (void)mdb_data_free(db, value_ptr, value_size);
                     (void)mdb_index_free(db, index_ptr);
                   });
    mdb_status_t ptr_update_status = mdb_write_nextptr(db, save_ptr, index_ptr);
    STAT_CHECK_RET(ptr_update_status, {
                     (void)mdb_data_free(db, value_ptr, value_size);
                     (void)mdb_index_free(db, index_ptr);
                   });

There will be inconsistency in database files if any of the allocation/write step fails, and the corresponding rollback steps fails too.
It is really necessary to distinguish between recoverable and non-recoverable (critical) errors. A bitmask would be fine.

@chuigda chuigda self-assigned this Feb 8, 2020
@chuigda chuigda transferred this issue from Pr65/project-scott Feb 23, 2020
@chuigda chuigda added 20RMB Fix this issue to win 20RMB! 30RMB Fix this issue to win 30 RMB! and removed 20RMB Fix this issue to win 20RMB! labels Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
30RMB Fix this issue to win 30 RMB!
Projects
None yet
Development

No branches or pull requests

1 participant