AbstractWriteRequest
statement.
WriteRequestTask.java の 47 行で定義されています。
Public メソッド | |
WriteRequestTask (int nbToComplete, int totalNb, AbstractWriteRequest request) | |
void | execute (BackendWorkerThread backendThread) throws SQLException |
int | getResult () |
String | toString () |
boolean | hasTid () |
synchronized void | notifySuccess () |
synchronized boolean | notifyFailure (BackendWorkerThread backendThread, long timeout, SQLException e) throws SQLException |
ArrayList | getExceptions () |
int | getFailed () |
int | getNbToComplete () |
int | getSuccess () |
int | getTotalNb () |
void | setTotalNb (int totalNb) |
void | setHasTid (boolean hasTid) |
Private 変数 | |
AbstractWriteRequest | request |
int | result |
|
Creates a new
WriteRequestTask.java の 59 行で定義されています。
00061 {
00062 super(nbToComplete, totalNb);
00063 this.request = request;
00064 }
|
|
Executes a write request with the given backend thread.
org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTaskに実装されています. WriteRequestTask.java の 72 行で定義されています。 参照先 org.objectweb.cjdbc.common.sql.schema.DatabaseSchema.addTable(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.disable(), java.sql.Statement.executeUpdate(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.getConnection(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionManager(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getDatabaseSchema(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getDriverCompliance(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getName(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQLShortForm(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getSQLShortFormLength(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getSuccess(), org.objectweb.cjdbc.common.sql.schema.DatabaseSchema.getTable(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.getTableName(), org.objectweb.cjdbc.common.sql.AbstractRequest.getTimeout(), org.objectweb.cjdbc.common.sql.AbstractRequest.getTransactionId(), org.objectweb.cjdbc.common.sql.AbstractRequest.isAutoCommit, org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isCreate(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isDrop(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.isStartedTransaction(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyFailure(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifySuccess(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.releaseConnection(), org.objectweb.cjdbc.common.sql.schema.DatabaseSchema.removeTable(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.retrieveConnection(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.rewriteQuery(), java.sql.Statement.setQueryTimeout(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.startTransaction(), と org.objectweb.cjdbc.controller.backend.DriverCompliance.supportSetQueryTimeout.
00073 { 00074 DatabaseBackend backend = backendThread.getBackend(); 00075 00076 AbstractConnectionManager cm = backend.getConnectionManager(request 00077 .getLogin()); 00078 00079 if (request.isAutoCommit()) 00080 { // Use a connection just for this request 00081 Connection c = null; 00082 try 00083 { 00084 c = cm.getConnection(); 00085 } 00086 catch (UnreachableBackendException e1) 00087 { 00088 backendThread.getLogger().error( 00089 "Disabling backend " + backend.getName() 00090 + " because it is no more reachable."); 00091 backend.disable(); 00092 throw new SQLException("Backend " + backend.getName() 00093 + " is no more reachable."); 00094 } 00095 00096 // Sanity check 00097 if (c == null) 00098 { 00099 SQLException se = new SQLException("No more connections"); 00100 try 00101 { // All backends failed, just ignore 00102 if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000, 00103 se)) 00104 return; 00105 } 00106 catch (SQLException ignore) 00107 { 00108 } 00109 // Disable this backend (it is no more in sync) by killing the backend 00110 // thread 00111 backendThread.kill(); 00112 String msg = "Request '" 00113 + request.getSQLShortForm(backend.getSQLShortFormLength()) 00114 + "' failed on backend " + backend.getName() + " but " 00115 + getSuccess() + " succeeded (" + se + ")"; 00116 backendThread.getLogger().error(msg); 00117 throw new SQLException(msg); 00118 } 00119 00120 // Execute Query 00121 try 00122 { 00123 Statement s = c.createStatement(); 00124 if (backend.getDriverCompliance().supportSetQueryTimeout()) 00125 s.setQueryTimeout(request.getTimeout()); 00126 00127 String sql = request.getSQL(); 00128 // Rewrite the query if needed 00129 sql = backend.rewriteQuery(sql); 00130 result = s.executeUpdate(sql); 00131 00132 // Update schema 00133 if (request.isCreate()) 00134 { // Add the table to the schema 00135 DatabaseSchema dbs = backend.getDatabaseSchema(); 00136 if (dbs != null) 00137 { 00138 DatabaseTable t = ((CreateRequest) request).getDatabaseTable(); 00139 if (t != null) 00140 { 00141 dbs.addTable(t); 00142 if (backendThread.getLogger().isDebugEnabled()) 00143 backendThread.getLogger().debug( 00144 "Added table '" + request.getTableName() 00145 + "' to backend database schema"); 00146 } 00147 } 00148 } 00149 else if (request.isDrop()) 00150 { // Delete the table from the schema 00151 DatabaseSchema dbs = backend.getDatabaseSchema(); 00152 if (dbs != null) 00153 { 00154 DatabaseTable t = dbs.getTable(request.getTableName()); 00155 if (t != null) 00156 { 00157 dbs.removeTable(t); 00158 if (backendThread.getLogger().isDebugEnabled()) 00159 backendThread.getLogger().debug( 00160 "Removed table '" + request.getTableName() 00161 + "' from backend database schema"); 00162 } 00163 } 00164 } 00165 } 00166 catch (SQLException e) 00167 { 00168 try 00169 { // All backends failed, just ignore 00170 if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000, 00171 e)) 00172 return; 00173 } 00174 catch (SQLException ignore) 00175 { 00176 } 00177 // Disable this backend (it is no more in sync) by killing the backend 00178 // thread 00179 backendThread.kill(); 00180 String msg = "Request '" 00181 + request.getSQLShortForm(backend.getSQLShortFormLength()) 00182 + "' failed on backend " + backend.getName() + " but " 00183 + getSuccess() + " succeeded (" + e + ")"; 00184 backendThread.getLogger().error(msg); 00185 throw new SQLException(msg); 00186 } 00187 finally 00188 { 00189 cm.releaseConnection(c); 00190 } 00191 } 00192 else 00193 { // Re-use the connection used by this transaction 00194 Connection c; 00195 long tid = request.getTransactionId(); 00196 Long lTid = new Long(tid); 00197 00198 if (!backend.isStartedTransaction(lTid)) 00199 { // Transaction has not been started yet, this is a lazy begin 00200 try 00201 { 00202 c = cm.getConnection(tid); 00203 } 00204 catch (UnreachableBackendException e1) 00205 { 00206 backendThread.getLogger().error( 00207 "Disabling backend " + backend.getName() 00208 + " because it is no more reachable."); 00209 backend.disable(); 00210 throw new SQLException("Backend " + backend.getName() 00211 + " is no more reachable."); 00212 } 00213 00214 // Sanity check 00215 if (c == null) 00216 { // Bad connection 00217 SQLException se = new SQLException( 00218 "Unable to get connection for transaction " + tid); 00219 try 00220 { // All backends failed, just ignore 00221 if (!notifyFailure(backendThread, 00222 (long) request.getTimeout() * 1000, se)) 00223 return; 00224 } 00225 catch (SQLException ignore) 00226 { 00227 } 00228 // Disable this backend (it is no more in sync) by killing the 00229 // backend thread 00230 backendThread.kill(); 00231 String msg = "Request '" 00232 + request.getSQLShortForm(backend.getSQLShortFormLength()) 00233 + "' failed on backend " + backend.getName() + " but " 00234 + getSuccess() + " succeeded (" + se + ")"; 00235 backendThread.getLogger().error(msg); 00236 throw new SQLException(msg); 00237 } 00238 00239 // begin transaction 00240 backend.startTransaction(lTid); 00241 c.setAutoCommit(false); 00242 } 00243 else 00244 { // Transaction has already been started, retrieve connection 00245 c = cm.retrieveConnection(tid); 00246 00247 // Sanity check 00248 if (c == null) 00249 { // Bad connection 00250 SQLException se = new SQLException( 00251 "Unable to retrieve connection for transaction " + tid); 00252 try 00253 { // All backends failed, just ignore 00254 if (!notifyFailure(backendThread, 00255 (long) request.getTimeout() * 1000, se)) 00256 return; 00257 } 00258 catch (SQLException ignore) 00259 { 00260 } 00261 // Disable this backend (it is no more in sync) by killing the 00262 // backend thread 00263 backendThread.kill(); 00264 String msg = "Request '" 00265 + request.getSQLShortForm(backend.getSQLShortFormLength()) 00266 + "' failed on backend " + backend.getName() + " but " 00267 + getSuccess() + " succeeded (" + se + ")"; 00268 backendThread.getLogger().error(msg); 00269 throw new SQLException(msg); 00270 } 00271 } 00272 00273 // Execute Query 00274 try 00275 { 00276 Statement s = c.createStatement(); 00277 if (backend.getDriverCompliance().supportSetQueryTimeout()) 00278 s.setQueryTimeout(request.getTimeout()); 00279 00280 String sql = request.getSQL(); 00281 // Rewrite the query if needed 00282 sql = backend.rewriteQuery(sql); 00283 result = s.executeUpdate(sql); 00284 00285 // Update schema 00286 if (request.isCreate()) 00287 { // Add the table to the schema 00288 DatabaseSchema dbs = backend.getDatabaseSchema(); 00289 if (dbs != null) 00290 { 00291 DatabaseTable t = ((CreateRequest) request).getDatabaseTable(); 00292 if (t != null) 00293 { 00294 dbs.addTable(t); 00295 if (backendThread.getLogger().isDebugEnabled()) 00296 backendThread.getLogger().debug( 00297 "Added table '" + request.getTableName() 00298 + "' to backend database schema"); 00299 } 00300 } 00301 } 00302 else if (request.isDrop()) 00303 { // Delete the table from the schema 00304 DatabaseSchema dbs = backend.getDatabaseSchema(); 00305 if (dbs != null) 00306 { 00307 DatabaseTable t = dbs.getTable(request.getTableName()); 00308 if (t != null) 00309 { 00310 dbs.removeTable(t); 00311 if (backendThread.getLogger().isDebugEnabled()) 00312 backendThread.getLogger().debug( 00313 "Removed table '" + request.getTableName() 00314 + "' from backend database schema"); 00315 } 00316 } 00317 } 00318 } 00319 catch (SQLException e) 00320 { 00321 try 00322 { // All backends failed, just ignore 00323 if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000, 00324 e)) 00325 return; 00326 } 00327 catch (SQLException ignore) 00328 { 00329 } 00330 // Disable this backend (it is no more in sync) by killing the backend 00331 // thread 00332 backendThread.kill(); 00333 String msg = "Request '" 00334 + request.getSQLShortForm(backend.getSQLShortFormLength()) 00335 + "' failed on backend " + backend.getName() + " but " 00336 + getSuccess() + " succeeded (" + e + ")"; 00337 backendThread.getLogger().error(msg); 00338 throw new SQLException(msg); 00339 } 00340 } 00341 notifySuccess(); 00342 } |
|
Returns the exceptions lists.
AbstractTask.java の 167 行で定義されています。 参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.exceptions.
00168 {
00169 return exceptions;
00170 }
|
|
|
Returns the number of threads that must succeed before returning.
AbstractTask.java の 187 行で定義されています。 参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.nbToComplete.
00188 {
00189 return nbToComplete;
00190 }
|
|
Returns the result.
WriteRequestTask.java の 349 行で定義されています。
00350 { 00351 return result; 00352 } |
|
|
Returns the total number of threads.
AbstractTask.java の 208 行で定義されています。 参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.totalNb.
00209 {
00210 return totalNb;
00211 }
|
|
Returns true if this task has a tid attached to it. Used internally by BackendWorkerThread.
AbstractTask.java の 231 行で定義されています。
00232 { 00233 return hasTid; 00234 } |
|
Notifies that the specified backendThread failed to execute this task. If all nodes failed, this method return
AbstractTask.java の 127 行で定義されています。 参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.exceptions, org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.failed, org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.success, と org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.totalNb. 参照元 org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.RollbackTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.BeginTask.execute(), と org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread.kill().
00129 { 00130 failed++; 00131 00132 // Log the exception 00133 if (exceptions == null) 00134 exceptions = new ArrayList(); 00135 exceptions.add(new SQLException("BackendThread " 00136 + backendThread.getBackend().getName() + " failed (" + e + ")")); 00137 00138 // Notify if needed 00139 if (success + failed == totalNb) 00140 { 00141 notifyAll(); // Notify all failed threads 00142 } 00143 else 00144 { 00145 try 00146 { // Wait to check if all other threads failed or not 00147 wait(timeout); 00148 } 00149 catch (InterruptedException ie) 00150 { 00151 throw new SQLException("Wait interrupted() in failed task of backend " 00152 + backendThread.getBackend().getName() + " (" + e + ")"); 00153 } 00154 } 00155 return success > 0; 00156 } |
|
|
Sets the hasTid value. Used internally by BackendWorkerThread.
AbstractTask.java の 243 行で定義されています。 参照元 org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread.addPriorityTask(), と org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread.addTask().
00244 {
00245 this.hasTid = hasTid;
00246 }
|
|
Sets the total number of threads.
AbstractTask.java の 219 行で定義されています。 参照元 org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.callStoredProcedure().
00220 {
00221 this.totalNb = totalNb;
00222 }
|
|
WriteRequestTask.java の 357 行で定義されています。 参照先 org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL().
00358 { 00359 return "WriteTask (" + request.getSQL() + ")"; 00360 } |
|
WriteRequestTask.java の 49 行で定義されています。 |
|
WriteRequestTask.java の 50 行で定義されています。 |