DbEnv.remove

APIRef

import com.sleepycat.db.*;
import java.io.FileNotFoundException;

public void remove(String db_home, int flags) throws DbException, FileNotFoundException;

Description

The DbEnv.remove method destroys a Berkeley DB environment if it is not currently in use. The environment regions, including any backing files, are removed. Any log or database files and the environment directory are not removed.

The db_home argument to DbEnv.remove is described in Berkeley DB File Naming.

If there are processes that have called DbEnv.open without calling DbEnv.close (that is, there are processes currently using the environment), DbEnv.remove will fail without further action unless the Db.DB_FORCE flag is set, in which case DbEnv.remove will attempt to remove the environment, regardless of any processes still using it.

The result of attempting to forcibly destroy the environment when it is in use is unspecified. Processes using an environment often maintain open file descriptors for shared regions within it. On UNIX systems, the environment removal will usually succeed, and processes that have already joined the region will continue to run in that region without change. However, processes attempting to join the environment will either fail or create new regions. On other systems in which the unlink(2) system call will fail if any process has an open file descriptor for the file (for example Windows/NT), the region removal will fail.

Calling DbEnv.remove should not be necessary for most applications because the Berkeley DB environment is cleaned up as part of normal database recovery procedures. However, applications may want to call DbEnv.remove as part of application shut down to free up system resources. For example, if the Db.DB_SYSTEM_MEM flag was specified to DbEnv.open, it may be useful to call DbEnv.remove in order to release system shared memory segments that have been allocated. Or, on architectures in which mutexes require allocation of underlying system resources, it may be useful to call DbEnv.remove in order to release those resources. Alternatively, if recovery is not required because no database state is maintained across failures, and no system resources need to be released, it is possible to clean up an environment by simply removing all the Berkeley DB files in the database environment's directories.

The flags value must be set to 0 or by bitwise inclusively OR'ing together one or more of the following values:

Db.DB_FORCE
If the Db.DB_FORCE flag is set, the environment is removed, regardless of any processes that may still using it, and no locks are acquired during this process. (Generally, the Db.DB_FORCE flag is specified only when applications were unable to shut down cleanly, and there is a risk that an application may have died holding a Berkeley DB lock.)

Db.DB_USE_ENVIRON
The Berkeley DB process' environment may be permitted to specify information to be used when naming files; see Berkeley DB File Naming. Because permitting users to specify which files are used can create security problems, environment information will be used in file naming for all users only if the DB_USE_ENVIRON flag is set.

Db.DB_USE_ENVIRON_ROOT
The Berkeley DB process' environment may be permitted to specify information to be used when naming files; see Berkeley DB File Naming. Because permitting users to specify which files are used can create security problems, if the DB_USE_ENVIRON_ROOT flag is set, environment information will be used for file naming only for users with appropriate permissions (for example, users with a user-ID of 0 on UNIX systems).

In multithreaded applications, only a single thread may call DbEnv.remove.

A DbEnv handle that has already been used to open an environment should not be used to call the DbEnv.remove method; a new DbEnv handle should be created for that purpose.

After DbEnv.remove has been called, regardless of its return, the Berkeley DB environment handle may not be accessed again.

The DbEnv.remove method throws an exception that encapsulates a non-zero error value on failure.

Errors

EBUSY
The shared memory region was in use and the force flag was not set.

If the file or directory does not exist, the DbEnv.remove method will fail and throw a FileNotFoundException exception.

The DbEnv.remove method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods. If a catastrophic error has occurred, the DbEnv.remove method may fail and throw a DbRunRecoveryException, in which case all subsequent Berkeley DB calls will fail in the same way.

Class

DbEnv

See Also

DbEnv.close, DbEnv.get_version_string, DbEnv.open, DbEnv.remove, DbEnv.set_cachesize, DbEnv.set_data_dir, DbEnv.set_errcall, DbEnv.set_error_stream, DbEnv.set_errpfx, DbEnv.set_feedback, DbEnv.set_flags, DbEnv.set_mutexlocks, DbEnv.set_pageyield, DbEnv.set_panicstate, DbEnv.set_recovery_init, DbEnv.set_rpc_server, DbEnv.set_region_init, DbEnv.set_shm_key, DbEnv.set_tas_spins, DbEnv.set_tmp_dir, DbEnv.set_verbose, and DbEnv.strerror.

APIRef

Copyright Sleepycat Software