|
25 | 25 | import java.util.Map;
|
26 | 26 |
|
27 | 27 | /**
|
28 |
| - * <p>WriteConcern control the write behavior for with various options, as well as exception raising on error conditions.</p> |
29 |
| - * |
| 28 | + * <p>WriteConcern control the acknowledgment of write operations with various options. |
30 | 29 | * <p>
|
31 | 30 | * <b>w</b>
|
32 | 31 | * <ul>
|
33 |
| - * <li>-1 = don't even report network errors </li> |
34 |
| - * <li> 0 = default, don't call getLastError by default </li> |
35 |
| - * <li> 1 = basic, call getLastError, but don't wait for slaves</li> |
36 |
| - * <li> 2+= wait for slaves </li> |
| 32 | + * <li>-1 = Don't even report network errors </li> |
| 33 | + * <li> 0 = Don't wait for acknowledgement from the server </li> |
| 34 | + * <li> 1 = Wait for acknowledgement, but don't wait for secondaries to replicate</li> |
| 35 | + * <li> 2+= Wait for one or more secondaries to also acknowledge </li> |
37 | 36 | * </ul>
|
38 | 37 | * <b>wtimeout</b> how long to wait for slaves before failing
|
39 | 38 | * <ul>
|
40 |
| - * <li>0 = indefinite </li> |
41 |
| - * <li>> 0 = ms to wait </li> |
| 39 | + * <li>0: indefinite </li> |
| 40 | + * <li>greater than 0: ms to wait </li> |
42 | 41 | * </ul>
|
43 | 42 | * </p>
|
44 |
| - * <p><b>fsync</b> force fsync to disk </p> |
45 |
| - * |
| 43 | + * <p> |
| 44 | + * Other options: |
| 45 | + * <ul> |
| 46 | + * <li><b>j</b>: wait for group commit to journal</li> |
| 47 | + * <li><b>fsync</b>: force fsync to disk</li> |
| 48 | + * </ul> |
46 | 49 | * @dochub databases
|
47 | 50 | */
|
48 | 51 | public class WriteConcern implements Serializable {
|
49 | 52 |
|
50 | 53 | private static final long serialVersionUID = 1884671104750417011L;
|
51 | 54 |
|
52 |
| - /** No exceptions are raised, even for network issues */ |
| 55 | + /** |
| 56 | + * Write operations that use this write concern will wait for acknowledgement from the primary server before returning. |
| 57 | + * Exceptions are raised for network issues, and server errors. |
| 58 | + * @since 2.10.0 |
| 59 | + */ |
| 60 | + public final static WriteConcern ACKNOWLEDGED = new WriteConcern(1); |
| 61 | + /** |
| 62 | + * Write operations that use this write concern will return as soon as the message is written to the socket. |
| 63 | + * Exceptions are raised for network issues, but not server errors. |
| 64 | + * @since 2.10.0 |
| 65 | + */ |
| 66 | + public final static WriteConcern UNACKNOWLEDGED = new WriteConcern(0); |
| 67 | + |
| 68 | + /** |
| 69 | + * No exceptions are raised, even for network issues. |
| 70 | + */ |
53 | 71 | public final static WriteConcern NONE = new WriteConcern(-1);
|
54 | 72 |
|
55 |
| - /** Exceptions are raised for network issues, but not server errors */ |
| 73 | + /** |
| 74 | + * Write operations that use this write concern will return as soon as the message is written to the socket. |
| 75 | + * Exceptions are raised for network issues, but not server errors. |
| 76 | + * <p> |
| 77 | + * This field has been superseded by {@code WriteConcern.UNACKNOWLEDGED}, and may be deprecated in a future release. |
| 78 | + * @see WriteConcern#UNACKNOWLEDGED |
| 79 | + */ |
56 | 80 | public final static WriteConcern NORMAL = new WriteConcern(0);
|
57 | 81 |
|
58 |
| - /** Exceptions are raised for network issues, and server errors; waits on a server for the write operation */ |
| 82 | + /** |
| 83 | + * Write operations that use this write concern will wait for acknowledgement from the primary server before returning. |
| 84 | + * Exceptions are raised for network issues, and server errors. |
| 85 | + * <p> |
| 86 | + * This field has been superseded by {@code WriteConcern.ACKNOWLEDGED}, and may be deprecated in a future release. |
| 87 | + * @see WriteConcern#ACKNOWLEDGED |
| 88 | + */ |
59 | 89 | public final static WriteConcern SAFE = new WriteConcern(1);
|
60 | 90 |
|
61 |
| - /** Exceptions are raised for network issues, but not server errors */ |
62 |
| - public final static WriteConcern UNACKNOWLEDGED = new WriteConcern(0); |
63 |
| - |
64 |
| - /** Exceptions are raised for network issues, and server errors; waits on a server for the write operation */ |
65 |
| - public final static WriteConcern ACKNOWLEDGED = new WriteConcern(1); |
66 |
| - |
67 |
| - /** Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation */ |
| 91 | + /** |
| 92 | + * Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation. |
| 93 | + */ |
68 | 94 | public final static WriteConcern MAJORITY = new Majority();
|
69 | 95 |
|
70 |
| - /** Exceptions are raised for network issues, and server errors; the write operation waits for the server to flush the data to disk*/ |
| 96 | + /** |
| 97 | + * Exceptions are raised for network issues, and server errors; the write operation waits for the server to flush |
| 98 | + * the data to disk. |
| 99 | + */ |
71 | 100 | public final static WriteConcern FSYNC_SAFE = new WriteConcern(true);
|
72 | 101 |
|
73 |
| - /** Exceptions are raised for network issues, and server errors; the write operation waits for the server to group commit to the journal file on disk*/ |
| 102 | + /** |
| 103 | + * Exceptions are raised for network issues, and server errors; the write operation waits for the server to |
| 104 | + * group commit to the journal file on disk. |
| 105 | + */ |
74 | 106 | public final static WriteConcern JOURNAL_SAFE = new WriteConcern( 1, 0, false, true );
|
75 | 107 |
|
76 |
| - /** Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation*/ |
| 108 | + /** |
| 109 | + * Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation. |
| 110 | + */ |
77 | 111 | public final static WriteConcern REPLICAS_SAFE = new WriteConcern(2);
|
78 | 112 |
|
79 | 113 | // map of the constants from above for use by fromString
|
80 | 114 | private static Map<String, WriteConcern> _namedConcerns = null;
|
81 | 115 |
|
82 | 116 | /**
|
83 |
| - * Default constructor keeping all options as default |
| 117 | + * Default constructor keeping all options as default. Be careful using this constructor, as it's equivalent to |
| 118 | + * {@code WriteConcern.UNACKNOWLEDGED}, so writes may be lost without any errors being reported. |
| 119 | + * @see WriteConcern#UNACKNOWLEDGED |
84 | 120 | */
|
85 | 121 | public WriteConcern(){
|
86 | 122 | this(0);
|
@@ -241,7 +277,6 @@ public WriteConcern( String w , int wtimeout , boolean fsync, boolean j, boolean
|
241 | 277 | public BasicDBObject getCommand() {
|
242 | 278 | BasicDBObject _command = new BasicDBObject( "getlasterror" , 1 );
|
243 | 279 |
|
244 |
| - |
245 | 280 | if (_w instanceof Integer && ((Integer) _w > 1) || (_w instanceof String)){
|
246 | 281 | _command.put( "w" , _w );
|
247 | 282 | }
|
|
0 commit comments