1 Reply Latest reply: Jul 29, 2014 8:24 PM by Winter Zhang RSS

    How do I properly turn off environment error callback?

    compmaniak

      Hello,

      I have experimented with DbEnv::set_errcall() function in 6.1.19 release and found a strange behaviour. The documentation says that verbose error message is written to stderr if error callback is not set for the environment. That's true. When an error callback is set, verbose error message is passed to appropriate function. That's true to. But when I unconfigure callback interface ( invoking 'set_errcal(nullptr)' ) verbose error messages are not written to srderr again.

       

      1) Here we try to delete a record with wrong number producing error messages to stderr

      size_t flags = DB_CREATE /* Create the environment if it does not exist */

        | DB_INIT_LOCK        /* Initialize the locking subsystem */

        | DB_INIT_LOG         /* Initialize the logging subsystem */

        | DB_INIT_TXN         /* Initialize the transactional subsystem. This also turns on logging. */

        | DB_INIT_MPOOL;      /* Initialize the memory pool (in-memory cache) */

      DbEnv env( DB_CXX_NO_EXCEPTIONS );

      env.open( "d:\\test", flags, 0 );

      Db db( &env, DB_CXX_NO_EXCEPTIONS );

      db.set_flags( DB_RENUMBER );

      db.open( nullptr,"test.bdb", nullptr, DB_RECNO, DB_AUTO_COMMIT | DB_CREATE | DB_READ_UNCOMMITTED, 0 );

      db_recno_t recno = 0;

      Dbt k( &recno, sizeof( db_recno_t ) );

      k.set_ulen( k.get_size() );

      k.set_flags( DB_DBT_USERMEM );

      db.del( nullptr, &k, 0 );

      db.del( nullptr, &k, 0 );

      db.del( nullptr, &k, 0 );


      Output:

      BDB1002 illegal record number of 0

      BDB1002 illegal record number of 0

      BDB1002 illegal record number of 0

       

      2) Here we do the same from ex. 1 but adding one meaningless string

      size_t flags = DB_CREATE /* Create the environment if it does not exist */

        | DB_INIT_LOCK        /* Initialize the locking subsystem */

        | DB_INIT_LOG         /* Initialize the logging subsystem */

        | DB_INIT_TXN         /* Initialize the transactional subsystem. This also turns on logging. */

        | DB_INIT_MPOOL;      /* Initialize the memory pool (in-memory cache) */

      DbEnv env( DB_CXX_NO_EXCEPTIONS );

      env.set_errcall( nullptr ); // <--- HAS NO SENSE IN THIS CONTEXT

      env.open( "d:\\test", flags, 0 );

      Db db( &env, DB_CXX_NO_EXCEPTIONS );

      db.set_flags( DB_RENUMBER );

      db.open( nullptr,"test.bdb", nullptr, DB_RECNO, DB_AUTO_COMMIT | DB_CREATE | DB_READ_UNCOMMITTED, 0 );

      db_recno_t recno = 0;

      Dbt k( &recno, sizeof( db_recno_t ) );

      k.set_ulen( k.get_size() );

      k.set_flags( DB_DBT_USERMEM );

      db.del( nullptr, &k, 0 );

      db.del( nullptr, &k, 0 );

      db.del( nullptr, &k, 0 );

       

      Output: <no output>

       

      In ex.2 I expected 3 error message to be written to stderr. What's wrong with the example? Setting error callback to NULL someway affects writting to stderr.

       

      Thanks.