1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2009 Oracle.  All rights reserved.
5 *
6 */
7using System;
8using System.Collections.Generic;
9using System.Text;
10using BerkeleyDB.Internal;
11
12namespace BerkeleyDB {
13    /// <summary>
14    /// A class representing the return value of
15    /// <see cref="DatabaseEnvironment.RepProcessMessage"/>.
16    /// </summary>
17    public class RepProcMsgResult {
18        /// <summary>
19        /// The result of processing an incoming replication message.
20        /// </summary>
21        public enum ProcMsgResult {
22            /// <summary>
23            /// The replication group has more than one master.
24            /// </summary>
25            /// <remarks>
26            /// The application should reconfigure itself as a client by calling
27            /// <see cref="DatabaseEnvironment.RepStartClient"/>,
28            /// and then call for an election using
29            /// <see cref="DatabaseEnvironment.RepHoldElection"/>.
30            /// </remarks>
31            DUPLICATE_MASTER,
32            /// <summary>
33            /// An unspecified error occurred.
34            /// </summary>
35            ERROR,
36            /// <summary>
37            /// An election is needed.
38            /// </summary>
39            /// <remarks>
40            /// The application should call for an election using
41            /// <see cref="DatabaseEnvironment.RepHoldElection"/>.
42            /// </remarks>
43            HOLD_ELECTION,
44            /// <summary>
45            /// A message cannot be processed.
46            /// </summary>
47            /// <remarks>
48            /// This is an indication that a message is irrelevant to the
49            /// current replication state (for example, an old message from a
50            /// previous generation arrives and is processed late).
51            /// </remarks>
52            IGNORED,
53            /// <summary>
54            /// Processing a message resulted in the processing of records that
55            /// are permanent.
56            /// </summary>
57            /// <remarks>
58            /// <see cref="RetLsn"/> is the maximum LSN of the permanent
59            /// records stored.
60            /// </remarks>
61            IS_PERMANENT,
62            /// <summary>
63            /// A new master has been chosen but the client is unable to
64            /// synchronize with the new master.
65            /// </summary>
66            /// <remarks>
67            /// Possibly because the client has been configured with
68            /// <see cref="ReplicationConfig.NoAutoInit"/> to turn off
69            /// automatic internal initialization.
70            /// </remarks>
71            JOIN_FAILURE,
72            /// <summary>
73            /// The system received contact information from a new environment.
74            /// </summary>
75            /// <remarks>
76            /// The rec parameter to
77            /// <see cref="DatabaseEnvironment.RepProcessMessage"/> contains the
78            /// opaque data specified in the cdata parameter to
79            /// <see cref="DatabaseEnvironment.RepStartClient"/>. The
80            /// application should take whatever action is needed to establish a
81            /// communication channel with this new environment.
82            /// </remarks>
83            NEW_SITE,
84            /// <summary>
85            /// A message carrying a DB_REP_PERMANENT flag was processed
86            /// successfully, but was not written to disk.
87            /// </summary>
88            /// <remarks>
89            /// <see cref="RetLsn"/> is the LSN of this record. The application
90            /// should take whatever action is deemed necessary to retain its
91            /// recoverability characteristics.
92            /// </remarks>
93            NOT_PERMANENT,
94            /// <summary>
95            /// Processing a message succeded.
96            /// </summary>
97            SUCCESS
98        };
99
100        /// <summary>
101        /// The result of processing an incoming replication message.
102        /// </summary>
103        public ProcMsgResult Result;
104        /// <summary>
105        /// The log sequence number of the permanent log message that could not
106        /// be written to disk if <see cref="Result"/> is
107        /// <see cref="ProcMsgResult.NOT_PERMANENT"/>. The largest log
108        /// sequence number of the permanent records that are now written to
109        /// disk as a result of processing the message, if
110        /// <see cref="Result"/> is
111        /// <see cref="ProcMsgResult.IS_PERMANENT"/>. In all other cases the
112        /// value is undefined.
113        /// </summary>
114        public LSN RetLsn;
115
116        internal RepProcMsgResult(int ret, LSN dblsn) {
117            RetLsn = null;
118            switch (ret) {
119                case DbConstants.DB_REP_DUPMASTER:
120                    Result = ProcMsgResult.DUPLICATE_MASTER;
121                    break;
122                case DbConstants.DB_REP_HOLDELECTION:
123                    Result = ProcMsgResult.HOLD_ELECTION;
124                    break;
125                case DbConstants.DB_REP_IGNORE:
126                    Result = ProcMsgResult.IGNORED;
127                    break;
128                case DbConstants.DB_REP_ISPERM:
129                    Result = ProcMsgResult.IS_PERMANENT;
130                    break;
131                case DbConstants.DB_REP_JOIN_FAILURE:
132                    Result = ProcMsgResult.JOIN_FAILURE;
133                    break;
134                case DbConstants.DB_REP_NEWSITE:
135                    Result = ProcMsgResult.NEW_SITE;
136                    break;
137                case DbConstants.DB_REP_NOTPERM:
138                    Result = ProcMsgResult.NOT_PERMANENT;
139                    break;
140                case 0:
141                    Result = ProcMsgResult.SUCCESS;
142                    break;
143                default:
144                    Result = ProcMsgResult.ERROR;
145                    break;
146            }
147        }
148    }
149}
150