public class Durability extends Object implements Serializable
NONE
) has no guarantees that the data
will survive a catastrophic server failure.
ACK
) ensures that the data has
been received by the server.
journalDurable(int)
) ensures that
the data is written to the server's journal before returning.
fsyncDurable(int)
) is to ensure that the data has
been fsync()'d to the server's disk.
replicaDurable(int)
), the
server ensure that the data has been received by 1 to
N
replicas in the replica set. Fine grain
control can be achieved by specifying a replication mode
instead of a count.Generally, increasing the level of durability decreases performance.
Modifier and Type | Field and Description |
---|---|
static Durability |
ACK
The durability that says no durability is required.
|
static String |
MAJORITY_MODE
Built in replication mode indicating that more than 50% of the MongoDB
replica set servers have received a write.
|
static Durability |
NONE
The durability that says no durability is required.
|
Modifier | Constructor and Description |
---|---|
protected |
Durability(boolean waitForFsync,
boolean waitForJournal,
int waitForReplicas,
int waitTimeoutMillis)
Create a new Durability.
|
protected |
Durability(boolean waitForFsync,
boolean waitForJournal,
String waitForReplicasByMode,
int waitTimeoutMillis)
Create a new Durability.
|
Modifier and Type | Method and Description |
---|---|
Document |
asDocument()
Returns a suitable getlasterror command's document.
|
boolean |
equals(Object object)
Determines if the passed object is of this same type as this object and
if so that its fields are equal.
|
static Durability |
fsyncDurable(int waitTimeoutMillis)
Creates an fsync() durability.
|
int |
getWaitForReplicas()
Returns if (value greater than zero) the durability requires that the
response wait for the data to be received by a replica and the number of
replicas of the data to wait for.
|
String |
getWaitForReplicasByMode()
If the value is non-
null then wait for the specified
replication mode configured on the server. |
int |
getWaitTimeoutMillis()
Returns the number of milliseconds to wait for the durability
requirements to be satisfied.
|
int |
hashCode()
Computes a reasonable hash code.
|
boolean |
isWaitForFsync()
Returns if the durability requires that the response wait for an fsync()
of the data on the server to complete.
|
boolean |
isWaitForJournal()
Returns if the durability requires that the response wait for the data to
be written to the server's journal.
|
boolean |
isWaitForReply()
Returns if the durability requires that the response wait for a reply
from the server but potentially no special server processing.
|
static Durability |
journalDurable(int waitTimeoutMillis)
Creates an journal durability.
|
protected boolean |
nullSafeEquals(Object rhs,
Object lhs)
Does a null safe equals comparison.
|
static Durability |
replicaDurable(boolean ensureJournaled,
int minimumReplicas,
int waitTimeoutMillis)
Creates a multiple replica durability.
|
static Durability |
replicaDurable(boolean ensureJournaled,
String waitForReplicasByMode,
int waitTimeoutMillis)
Creates a multiple replica durability.
|
static Durability |
replicaDurable(int waitTimeoutMillis)
Creates a single replica durability.
|
static Durability |
replicaDurable(int minimumReplicas,
int waitTimeoutMillis)
Creates a multiple replica durability.
|
static Durability |
replicaDurable(String waitForReplicasByMode,
int waitTimeoutMillis)
Creates a multiple replica durability.
|
String |
toString() |
static Durability |
valueOf(String value)
Converts a string into a Durability, if possible.
|
public static final Durability ACK
public static final String MAJORITY_MODE
public static final Durability NONE
protected Durability(boolean waitForFsync, boolean waitForJournal, int waitForReplicas, int waitTimeoutMillis)
waitForFsync
- True if the durability requires that the response wait for an
fsync() of the data to complete, false otherwise.waitForJournal
- True if if the durability requires that the response wait for
the data to be written to the server's journal, false
otherwise.waitForReplicas
- If the value is value greater than zero the durability
requires that the response wait for the data to be received by
a replica and the number of replicas of the data to wait for.waitTimeoutMillis
- The number of milliseconds to wait for the durability
requirements to be satisfied.protected Durability(boolean waitForFsync, boolean waitForJournal, String waitForReplicasByMode, int waitTimeoutMillis)
waitForFsync
- True if the durability requires that the response wait for an
fsync() of the data to complete, false otherwise.waitForJournal
- True if if the durability requires that the response wait for
the data to be written to the server's journal, false
otherwise.waitForReplicasByMode
- If the value is non-null
then wait for the
specified replication mode configured on the server. A
built-in mode of MAJORITY_MODE
is also supported.waitTimeoutMillis
- The number of milliseconds to wait for the durability
requirements to be satisfied.public static Durability fsyncDurable(int waitTimeoutMillis)
Will cause the server to wait for the write to be sync'd to disk. If the server is running with journaling enabled then only the journal will have been sync'd to disk. If running without journaling enabled then will wait for all data files to be sync'd to disk.
waitTimeoutMillis
- The number of milliseconds to wait for the durability
requirements to be satisfied.public static Durability journalDurable(int waitTimeoutMillis)
Will cause the server to wait for the write to be sync'd to disk as part
of the journal. As of MongoDB 2.6 this mode will cause a TBD exception to
be thrown if the server is configured without journaling enabled. Prior
to MongoDB 2.6 this mode would silently degrade to ACK
.
waitTimeoutMillis
- The number of milliseconds to wait for the durability
requirements to be satisfied.public static Durability replicaDurable(boolean ensureJournaled, int minimumReplicas, int waitTimeoutMillis)
ensureJournaled
- If true then ensure that the write has been committed to the
journal in addition to replicated.minimumReplicas
- The minimum number of replicas to wait for.waitTimeoutMillis
- The number of milliseconds to wait for the durability
requirements to be satisfied.public static Durability replicaDurable(boolean ensureJournaled, String waitForReplicasByMode, int waitTimeoutMillis)
ensureJournaled
- If true then ensure that the write has been committed to the
journal in addition to replicated.waitForReplicasByMode
- If the value is non-null
then wait for the
specified replication mode configured on the server. A
built-in mode of MAJORITY_MODE
is also supported.waitTimeoutMillis
- The number of milliseconds to wait for the durability
requirements to be satisfied.public static Durability replicaDurable(int waitTimeoutMillis)
waitTimeoutMillis
- The number of milliseconds to wait for the durability
requirements to be satisfied.public static Durability replicaDurable(int minimumReplicas, int waitTimeoutMillis)
minimumReplicas
- The minimum number of replicas to wait for.waitTimeoutMillis
- The number of milliseconds to wait for the durability
requirements to be satisfied.public static Durability replicaDurable(String waitForReplicasByMode, int waitTimeoutMillis)
waitForReplicasByMode
- If the value is non-null
then wait for the
specified replication mode configured on the server. A
built-in mode of MAJORITY_MODE
is also supported.waitTimeoutMillis
- The number of milliseconds to wait for the durability
requirements to be satisfied.public static Durability valueOf(String value)
Two forms of strings can be converted:
ACK
NONE
SAFE
- for compatibility with the MongoDB Inc. driver,
returns ACK
.getlasterror
command:
w
wtimeout
fsync
j
getlasterror
getlasterror
field is ignored. An example JSON
document might look like: { w : 'majority', wtimeout : 10000 }
If the string is not parse-able in either of these forms then null is returned.
value
- The string representation of the Durability.public Document asDocument()
public boolean equals(Object object)
equals
in class Object
object
- The object to compare to.Object.equals(java.lang.Object)
public int getWaitForReplicas()
public String getWaitForReplicasByMode()
null
then wait for the specified
replication mode configured on the server. A built-in mode of
MAJORITY_MODE
is also supported.public int getWaitTimeoutMillis()
public int hashCode()
public boolean isWaitForFsync()
public boolean isWaitForJournal()
public boolean isWaitForReply()
public String toString()
Overriden to return the durability as JSON text.
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.