00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.controller.requestmanager;
00026
00027 import java.sql.SQLException;
00028 import java.util.ArrayList;
00029 import java.util.Hashtable;
00030
00031 import javax.management.NotCompliantMBeanException;
00032
00033 import org.objectweb.cjdbc.common.exceptions.BackupException;
00034 import org.objectweb.cjdbc.common.exceptions.ExceptionTypes;
00035 import org.objectweb.cjdbc.common.exceptions.NoMoreBackendException;
00036 import org.objectweb.cjdbc.common.exceptions.OctopusException;
00037 import org.objectweb.cjdbc.common.exceptions.RollbackException;
00038 import org.objectweb.cjdbc.common.i18n.Translate;
00039 import org.objectweb.cjdbc.common.jmx.JmxConstants;
00040 import org.objectweb.cjdbc.common.jmx.mbeans.RequestManagerMBean;
00041 import org.objectweb.cjdbc.common.log.Trace;
00042 import org.objectweb.cjdbc.common.shared.BackendState;
00043 import org.objectweb.cjdbc.common.shared.BackupListener;
00044 import org.objectweb.cjdbc.common.sql.AbstractWriteRequest;
00045 import org.objectweb.cjdbc.common.sql.AlterRequest;
00046 import org.objectweb.cjdbc.common.sql.CreateRequest;
00047 import org.objectweb.cjdbc.common.sql.ParsingGranularities;
00048 import org.objectweb.cjdbc.common.sql.RequestType;
00049 import org.objectweb.cjdbc.common.sql.SelectRequest;
00050 import org.objectweb.cjdbc.common.sql.StoredProcedure;
00051 import org.objectweb.cjdbc.common.sql.UpdateRequest;
00052 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema;
00053 import org.objectweb.cjdbc.common.sql.schema.DatabaseTable;
00054 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00055 import org.objectweb.cjdbc.common.xml.XmlComponent;
00056 import org.objectweb.cjdbc.controller.backend.BackendStateListener;
00057 import org.objectweb.cjdbc.controller.backend.DatabaseBackend;
00058 import org.objectweb.cjdbc.controller.backup.BackupManager;
00059 import org.objectweb.cjdbc.controller.cache.metadata.MetadataCache;
00060 import org.objectweb.cjdbc.controller.cache.parsing.ParsingCache;
00061 import org.objectweb.cjdbc.controller.cache.result.AbstractResultCache;
00062 import org.objectweb.cjdbc.controller.cache.result.entries.CacheEntry;
00063 import org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean;
00064 import org.objectweb.cjdbc.controller.jmx.MBeanServerManager;
00065 import org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer;
00066 import org.objectweb.cjdbc.controller.loadbalancer.AllBackendsFailedException;
00067 import org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog;
00068 import org.objectweb.cjdbc.controller.recoverylog.BackendRecoveryInfo;
00069 import org.objectweb.cjdbc.controller.recoverylog.JDBCRecoverThread;
00070 import org.objectweb.cjdbc.controller.scheduler.AbstractScheduler;
00071 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet;
00072 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 public class RequestManager extends AbstractStandardMBean
00087 implements
00088 XmlComponent,
00089 RequestManagerMBean
00090 {
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 protected long beginTimeout;
00105
00106
00107 protected long commitTimeout;
00108
00109
00110 protected long rollbackTimeout;
00111
00112
00113 protected VirtualDatabase vdb;
00114
00115
00116 protected AbstractScheduler scheduler;
00117
00118
00119 protected AbstractResultCache resultCache;
00120
00121
00122 protected AbstractLoadBalancer loadBalancer;
00123
00124
00125 protected AbstractRecoveryLog recoveryLog;
00126
00127
00128 protected BackupManager backupManager;
00129
00130
00131 protected DatabaseSchema dbs;
00132
00133 private boolean schemaIsStatic = false;
00134
00135 private boolean isCaseSensitiveParsing = false;
00136
00137 protected ParsingCache parsingCache = null;
00138
00139 private MetadataCache metadataCache = null;
00140
00141
00142
00143 protected int schedulerParsingranularity = ParsingGranularities.NO_PARSING;
00144
00145 private int cacheParsingranularity = ParsingGranularities.NO_PARSING;
00146
00147 private int loadBalancerParsingranularity = ParsingGranularities.NO_PARSING;
00148
00149 protected int requiredGranularity = ParsingGranularities.NO_PARSING;
00150
00151
00152 protected Hashtable tidLoginTable;
00153
00154 protected static Trace logger = null;
00155
00156 private BackendStateListener backendStateListener;
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 public RequestManager(VirtualDatabase vdb, AbstractScheduler scheduler,
00177 AbstractResultCache cache, AbstractLoadBalancer loadBalancer,
00178 AbstractRecoveryLog recoveryLog, long beginTimeout, long commitTimeout,
00179 long rollbackTimeout) throws SQLException, NotCompliantMBeanException
00180 {
00181 super(RequestManagerMBean.class);
00182 this.vdb = vdb;
00183 assignAndCheckSchedulerLoadBalancerValidity(scheduler, loadBalancer);
00184
00185 this.resultCache = cache;
00186 if (resultCache != null)
00187 {
00188 cacheParsingranularity = cache.getParsingGranularity();
00189 if (cacheParsingranularity > requiredGranularity)
00190 requiredGranularity = cacheParsingranularity;
00191 }
00192 setRecoveryLog(recoveryLog);
00193 initRequestManagerVariables(vdb, beginTimeout, commitTimeout,
00194 rollbackTimeout);
00195 setBackendsLastKnownCheckpointFromRecoveryLog();
00196 logger.info(Translate.get("requestmanager.parsing.granularity",
00197 ParsingGranularities.getInformation(requiredGranularity)));
00198
00199 if (MBeanServerManager.isJmxEnabled())
00200 {
00201 try
00202 {
00203 MBeanServerManager.registerMBean(this, JmxConstants
00204 .getRequestManagerObjectName(vdb.getVirtualDatabaseName()));
00205
00206 }
00207 catch (Exception e)
00208 {
00209 logger.error(Translate.get("jmx.failed.register.mbean.requestmanager"));
00210 }
00211 }
00212 }
00213
00214
00215
00216
00217
00218 private void setBackendsLastKnownCheckpointFromRecoveryLog()
00219 {
00220
00221 if (recoveryLog == null)
00222 return;
00223 String databaseName = vdb.getVirtualDatabaseName();
00224 ArrayList backends = vdb.getBackends();
00225 int size = backends.size();
00226 DatabaseBackend backend;
00227 BackendRecoveryInfo info;
00228 for (int i = 0; i < size; i++)
00229 {
00230 backend = (DatabaseBackend) backends.get(i);
00231 try
00232 {
00233 info = recoveryLog.getBackendRecoveryInfo(databaseName, backend
00234 .getName());
00235 backend.setLastKnownCheckpoint(info.getCheckpoint());
00236 }
00237 catch (SQLException e)
00238 {
00239 logger.error(Translate.get("requestmanager.checkpoint.not.found",
00240 backend.getName()), e);
00241 }
00242 }
00243
00244 }
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 private void assignAndCheckSchedulerLoadBalancerValidity(
00255 AbstractScheduler scheduler, AbstractLoadBalancer loadBalancer)
00256 throws SQLException
00257 {
00258 if (scheduler == null)
00259 throw new SQLException(Translate.get("requestmanager.null.scheduler"));
00260
00261 if (loadBalancer == null)
00262 throw new SQLException(Translate.get("requestmanager.null.loadbalancer"));
00263
00264 if (scheduler.getRAIDbLevel() != loadBalancer.getRAIDbLevel())
00265 throw new SQLException(Translate.get(
00266 "requestmanager.incompatible.raidb.levels",
00267 new String[]{"" + scheduler.getRAIDbLevel(),
00268 "" + loadBalancer.getRAIDbLevel()}));
00269
00270
00271 setScheduler(scheduler);
00272 schedulerParsingranularity = scheduler.getParsingGranularity();
00273 requiredGranularity = schedulerParsingranularity;
00274 setLoadBalancer(loadBalancer);
00275 loadBalancerParsingranularity = loadBalancer.getParsingGranularity();
00276 if (loadBalancerParsingranularity > requiredGranularity)
00277 requiredGranularity = loadBalancerParsingranularity;
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 private void initRequestManagerVariables(VirtualDatabase vdb,
00289 long beginTimeout, long commitTimeout, long rollbackTimeout)
00290 {
00291 this.tidLoginTable = new Hashtable();
00292 this.beginTimeout = beginTimeout;
00293 this.commitTimeout = commitTimeout;
00294 this.rollbackTimeout = rollbackTimeout;
00295 this.vdb = vdb;
00296 logger = Trace.getLogger("org.objectweb.cjdbc.controller.RequestManager."
00297 + vdb.getDatabaseName());
00298 }
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 public ControllerResultSet execReadRequest(SelectRequest request)
00313 throws SQLException
00314 {
00315
00316 if (!request.isAutoCommit())
00317 {
00318
00319 long tid = request.getTransactionId();
00320 if (!tidLoginTable.containsKey(new Long(tid)))
00321 throw new SQLException(Translate.get("transaction.not.started", tid));
00322 }
00323
00324
00325
00326
00327
00328
00329 if ((requiredGranularity != ParsingGranularities.NO_PARSING)
00330 && (!request.isParsed()))
00331 {
00332 if (parsingCache == null)
00333 request.parse(dbs, requiredGranularity, isCaseSensitiveParsing);
00334 else
00335 parsingCache.getParsingFromCache(request);
00336 }
00337
00338
00339
00340
00341
00342
00343
00344
00345 if ((schedulerParsingranularity != ParsingGranularities.NO_PARSING)
00346 && !request.isParsed())
00347 {
00348 if (parsingCache == null)
00349 request.parse(dbs, requiredGranularity, isCaseSensitiveParsing);
00350 else
00351 parsingCache.getParsingFromCacheAndParseIfMissing(request);
00352 }
00353
00354 if (logger.isDebugEnabled())
00355 logger.debug(Translate.get("requestmanager.read.request.schedule",
00356 new String[]{String.valueOf(request.getId()),
00357 request.getSQLShortForm(vdb.getSQLShortFormLength())}));
00358
00359
00360 scheduler.scheduleReadRequest(request);
00361
00362
00363
00364
00365
00366 ControllerResultSet result = null;
00367 try
00368 {
00369 if (resultCache != null)
00370 {
00371 if (logger.isDebugEnabled())
00372 logger.debug(Translate.get("requestmanager.read.request.cache.get",
00373 new String[]{String.valueOf(request.getId()),
00374 request.getSQLShortForm(vdb.getSQLShortFormLength())}));
00375
00376 CacheEntry qce = resultCache.getFromCache(request, true);
00377 if (qce != null)
00378 {
00379 result = qce.getResult();
00380 if (result != null)
00381 {
00382 if (vdb.getSQLMonitor() != null)
00383 vdb.getSQLMonitor().logCacheHit(request);
00384
00385 scheduler.readCompleted(request);
00386 return result;
00387 }
00388 }
00389 }
00390
00391
00392
00393
00394
00395 if (logger.isDebugEnabled())
00396 logger.debug(Translate.get("requestmanager.read.request.balance",
00397 new String[]{String.valueOf(request.getId()),
00398 request.getSQLShortForm(vdb.getSQLShortFormLength())}));
00399
00400
00401
00402
00403
00404 if ((loadBalancerParsingranularity != ParsingGranularities.NO_PARSING)
00405 && !request.isParsed())
00406 {
00407 if (parsingCache == null)
00408 request.parse(dbs, requiredGranularity, isCaseSensitiveParsing);
00409 else
00410 parsingCache.getParsingFromCacheAndParseIfMissing(request);
00411 }
00412
00413
00414 result = loadBalancer.execReadRequest(request, metadataCache);
00415
00416
00417
00418
00419
00420
00421 if ((resultCache != null)
00422 && (request.getCacheAbility() != RequestType.UNCACHEABLE))
00423 {
00424 if (logger.isDebugEnabled())
00425 logger.debug(Translate.get(
00426 "requestmanager.read.request.cache.update", new String[]{
00427 String.valueOf(request.getId()),
00428 request.getSQLShortForm(vdb.getSQLShortFormLength())}));
00429
00430 if (!request.isParsed()
00431 && (cacheParsingranularity != ParsingGranularities.NO_PARSING))
00432 {
00433
00434 {
00435 if (parsingCache == null)
00436 request.parse(dbs, requiredGranularity, isCaseSensitiveParsing);
00437 else
00438 parsingCache.getParsingFromCacheAndParseIfMissing(request);
00439 }
00440 }
00441 resultCache.addToCache(request, result);
00442 }
00443 }
00444 catch (Exception failed)
00445 {
00446 if (resultCache != null)
00447 resultCache.removeFromPendingQueries(request);
00448 scheduler.readCompleted(request);
00449 if (failed instanceof NoMoreBackendException)
00450 throw (NoMoreBackendException) failed;
00451 String msg = Translate.get("requestmanager.request.failed", new String[]{
00452 request.getSQLShortForm(vdb.getSQLShortFormLength()),
00453 failed.getMessage()});
00454 if (failed instanceof RuntimeException)
00455 logger.warn(msg, failed);
00456 else
00457 logger.warn(msg);
00458 if (failed instanceof SQLException)
00459 throw (SQLException) failed;
00460
00461 throw new SQLException(msg);
00462 }
00463
00464
00465 scheduler.readCompleted(request);
00466
00467 return result;
00468 }
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479 public int execWriteRequest(AbstractWriteRequest request) throws SQLException
00480 {
00481 scheduleExecWriteRequest(request);
00482 int execWriteRequestResult = 0;
00483 try
00484 {
00485 execWriteRequestResult = loadBalanceExecWriteRequest(request);
00486 }
00487 catch (AllBackendsFailedException e)
00488 {
00489 String msg = Translate
00490 .get("requestmanager.write.request.failed.unexpected");
00491 logger.fatal(msg, e);
00492 throw new RuntimeException(msg, e);
00493 }
00494 updateAndNotifyExecWriteRequest(request, true);
00495 return execWriteRequestResult;
00496 }
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507 public ControllerResultSet execWriteRequestWithKeys(
00508 AbstractWriteRequest request) throws SQLException
00509 {
00510 scheduleExecWriteRequest(request);
00511 ControllerResultSet execWriteRequestWithKeysResult = null;
00512 try
00513 {
00514 execWriteRequestWithKeysResult = loadBalanceExecWriteRequestWithKeys(request);
00515 }
00516 catch (AllBackendsFailedException e)
00517 {
00518 String msg = Translate
00519 .get("requestmanager.write.request.keys.failed.unexpected");
00520 logger.fatal(msg, e);
00521 throw new RuntimeException(msg, e);
00522 }
00523 updateAndNotifyExecWriteRequest(request, true);
00524 return execWriteRequestWithKeysResult;
00525 }
00526
00527
00528
00529
00530
00531
00532
00533 public void scheduleExecWriteRequest(AbstractWriteRequest request)
00534 throws SQLException
00535 {
00536
00537 if (!request.isAutoCommit())
00538 {
00539
00540 long tid = request.getTransactionId();
00541 if (!tidLoginTable.containsKey(new Long(tid)))
00542 throw new SQLException(Translate.get("transaction.not.started", tid));
00543 }
00544
00545
00546
00547
00548
00549
00550 if ((requiredGranularity != ParsingGranularities.NO_PARSING)
00551 && (!request.isParsed()))
00552 {
00553 if (parsingCache == null)
00554 request.parse(dbs, requiredGranularity, isCaseSensitiveParsing);
00555 else
00556 parsingCache.getParsingFromCache(request);
00557 }
00558
00559
00560
00561
00562
00563
00564
00565
00566 if ((schedulerParsingranularity != ParsingGranularities.NO_PARSING)
00567 && !request.isParsed())
00568 {
00569 if (parsingCache == null)
00570 request.parse(dbs, requiredGranularity, isCaseSensitiveParsing);
00571 else
00572 parsingCache.getParsingFromCacheAndParseIfMissing(request);
00573 }
00574
00575 if (logger.isDebugEnabled())
00576 logger.debug(Translate.get("requestmanager.write.request.schedule",
00577 new String[]{String.valueOf(request.getId()),
00578 request.getSQLShortForm(vdb.getSQLShortFormLength())}));
00579
00580
00581 try
00582 {
00583 scheduler.scheduleWriteRequest(request);
00584 }
00585 catch (RollbackException e)
00586 {
00587
00588 rollback(request.getTransactionId());
00589 throw new SQLException(e.getMessage());
00590 }
00591
00592
00593
00594
00595
00596
00597 try
00598 {
00599 if ((requiredGranularity != ParsingGranularities.NO_PARSING)
00600 && !request.isParsed())
00601 {
00602 if (parsingCache == null)
00603 request.parse(dbs, requiredGranularity, isCaseSensitiveParsing);
00604 else
00605 parsingCache.getParsingFromCacheAndParseIfMissing(request);
00606 }
00607 }
00608 catch (SQLException e)
00609 {
00610
00611 scheduler.writeCompleted(request);
00612 throw e;
00613 }
00614 }
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626 public ControllerResultSet loadBalanceExecWriteRequestWithKeys(
00627 AbstractWriteRequest request) throws AllBackendsFailedException,
00628 SQLException
00629 {
00630 if (logger.isDebugEnabled())
00631 logger.debug(Translate.get("requestmanager.write.request.balance",
00632 new String[]{String.valueOf(request.getId()),
00633 request.getSQLShortForm(vdb.getSQLShortFormLength())}));
00634
00635 try
00636 {
00637 return loadBalancer.execWriteRequestWithKeys(request, metadataCache);
00638 }
00639 catch (Exception failed)
00640 {
00641 scheduler.writeCompleted(request);
00642 String msg = Translate.get("requestmanager.request.failed", new String[]{
00643 request.getSQLShortForm(vdb.getSQLShortFormLength()),
00644 failed.getMessage()});
00645 if (failed instanceof RuntimeException)
00646 logger.warn(msg, failed);
00647 else
00648 logger.warn(msg);
00649 if (failed instanceof AllBackendsFailedException)
00650 throw (AllBackendsFailedException) failed;
00651 else
00652 throw new SQLException(msg);
00653 }
00654 }
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666 public int loadBalanceExecWriteRequest(AbstractWriteRequest request)
00667 throws AllBackendsFailedException, SQLException
00668 {
00669 if (logger.isDebugEnabled())
00670 logger.debug(Translate.get("requestmanager.write.request.balance",
00671 new String[]{String.valueOf(request.getId()),
00672 request.getSQLShortForm(vdb.getSQLShortFormLength())}));
00673
00674 try
00675 {
00676 if (request.isUpdate() && (resultCache != null))
00677 {
00678
00679 if (!resultCache.isUpdateNecessary((UpdateRequest) request))
00680 return 0;
00681 }
00682 return loadBalancer.execWriteRequest(request);
00683 }
00684 catch (Exception failed)
00685 {
00686 scheduler.writeCompleted(request);
00687 String msg = Translate.get("requestmanager.request.failed", new String[]{
00688 request.getSQLShortForm(vdb.getSQLShortFormLength()),
00689 failed.getMessage()});
00690 if (failed instanceof RuntimeException)
00691 logger.warn(msg, failed);
00692 else
00693 logger.warn(msg);
00694 if (failed instanceof AllBackendsFailedException)
00695 throw (AllBackendsFailedException) failed;
00696 else if (failed instanceof SQLException)
00697 throw (SQLException) failed;
00698 else
00699 throw new SQLException(msg);
00700 }
00701 }
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716 public void updateAndNotifyExecWriteRequest(AbstractWriteRequest request,
00717 boolean notifyRecoveryLogAndScheduler) throws SQLException
00718 {
00719
00720 try
00721 {
00722 if (resultCache != null)
00723 {
00724 if (logger.isDebugEnabled())
00725 logger.debug(Translate.get(
00726 "requestmanager.write.request.cache.update", new String[]{
00727 String.valueOf(request.getId()),
00728 request.getSQLShortForm(vdb.getSQLShortFormLength())}));
00729
00730 resultCache.writeNotify(request);
00731 }
00732
00733
00734 if (notifyRecoveryLogAndScheduler && (recoveryLog != null))
00735 {
00736 if (logger.isDebugEnabled())
00737 logger.debug(Translate.get("requestmanager.write.request.log",
00738 new String[]{String.valueOf(request.getId()),
00739 request.getSQLShortForm(vdb.getSQLShortFormLength())}));
00740
00741 recoveryLog.logRequest(request);
00742 }
00743
00744
00745 if (requiredGranularity != ParsingGranularities.NO_PARSING)
00746 {
00747 if (request.isCreate())
00748 {
00749 dbs.addTable(((CreateRequest) request).getDatabaseTable());
00750 if (logger.isDebugEnabled())
00751 logger.debug(Translate.get("requestmanager.schema.add.table",
00752 request.getTableName()));
00753 }
00754 else if (request.isDrop())
00755 {
00756
00757 dbs.removeTable(dbs.getTable(request.getTableName()));
00758 if (logger.isDebugEnabled())
00759 logger.debug(Translate.get("requestmanager.schema.remove.table",
00760 request.getTableName()));
00761 }
00762 else if (request.isAlter()
00763 && (requiredGranularity > ParsingGranularities.TABLE))
00764 {
00765
00766 AlterRequest req = (AlterRequest) request;
00767 if (req.isDrop())
00768 dbs.getTable(req.getTableName()).remove(req.getColumn().getName());
00769 else if (req.isAdd())
00770 {
00771 dbs.getTable(req.getTableName()).addColumn(req.getColumn());
00772 }
00773 }
00774 }
00775
00776
00777 if (notifyRecoveryLogAndScheduler)
00778 scheduler.writeCompleted(request);
00779
00780 }
00781 catch (Exception failed)
00782 {
00783 scheduler.writeCompleted(request);
00784 String msg = Translate.get("requestmanager.request.failed", new String[]{
00785 request.getSQLShortForm(vdb.getSQLShortFormLength()),
00786 failed.getMessage()});
00787 if (failed instanceof RuntimeException)
00788 logger.warn(msg, failed);
00789 else
00790 logger.warn(msg);
00791 throw new SQLException(msg);
00792 }
00793 }
00794
00795
00796
00797
00798
00799
00800
00801
00802 public ControllerResultSet execReadStoredProcedure(StoredProcedure proc)
00803 throws SQLException
00804 {
00805
00806 if (!proc.isAutoCommit())
00807 {
00808
00809 long tid = proc.getTransactionId();
00810 if (!tidLoginTable.containsKey(new Long(tid)))
00811 throw new SQLException(Translate.get("transaction.not.started", tid));
00812 }
00813
00814
00815
00816
00817
00818
00819
00820
00821 SelectRequest spanOnAllTables = null;
00822 if (requiredGranularity != ParsingGranularities.NO_PARSING)
00823 {
00824 String sql = "SELECT * FROM";
00825 ArrayList tables = dbs.getTables();
00826 int size = tables.size();
00827
00828
00829
00830 for (int i = 0; i < size; i++)
00831 sql += " ," + ((DatabaseTable) tables.get(i)).getName();
00832
00833 spanOnAllTables = new SelectRequest(sql, false, 0, proc
00834 .getLineSeparator());
00835 }
00836 else
00837 spanOnAllTables = new SelectRequest("select * from x", false, 0, proc
00838 .getLineSeparator());
00839
00840
00841 scheduler.scheduleReadRequest(spanOnAllTables);
00842
00843 if (logger.isDebugEnabled())
00844 logger.debug(Translate.get("requestmanager.read.store.procedure",
00845 new String[]{String.valueOf(proc.getId()),
00846 proc.getSQLShortForm(vdb.getSQLShortFormLength())}));
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856 if ((resultCache != null) && (!proc.isReadOnly()))
00857 resultCache.flushCache();
00858
00859 ControllerResultSet result = null;
00860 try
00861 {
00862
00863
00864
00865
00866
00867 if (proc.isReadOnly())
00868 result = loadBalancer.execReadOnlyReadStoredProcedure(proc,
00869 metadataCache);
00870 else
00871 result = loadBalancer.execReadStoredProcedure(proc, metadataCache);
00872
00873
00874
00875
00876
00877 if (recoveryLog != null)
00878 recoveryLog.logRequest(proc, true);
00879
00880 }
00881 catch (Exception failed)
00882 {
00883 scheduler.readCompleted(spanOnAllTables);
00884 String msg = Translate.get("requestmanager.store.procedure.failed",
00885 new String[]{proc.getSQLShortForm(vdb.getSQLShortFormLength()),
00886 failed.getMessage()});
00887 logger.warn(msg);
00888 if (failed instanceof SQLException)
00889 {
00890 throw (SQLException) failed;
00891 }
00892 throw new SQLException(msg);
00893 }
00894
00895
00896 scheduler.readCompleted(spanOnAllTables);
00897
00898 return result;
00899 }
00900
00901
00902
00903
00904
00905
00906
00907
00908 public int execWriteStoredProcedure(StoredProcedure proc) throws SQLException
00909 {
00910
00911 if (!proc.isAutoCommit())
00912 {
00913
00914 long tid = proc.getTransactionId();
00915 if (!tidLoginTable.containsKey(new Long(tid)))
00916 throw new SQLException(Translate.get("transaction.not.started", String
00917 .valueOf(tid)));
00918 }
00919
00920
00921
00922
00923
00924
00925
00926
00927 SelectRequest spanOnAllTables = null;
00928 if (requiredGranularity != ParsingGranularities.NO_PARSING)
00929 {
00930 String sql = "SELECT * FROM";
00931 ArrayList tables = dbs.getTables();
00932 int size = tables.size();
00933
00934
00935
00936 for (int i = 0; i < size; i++)
00937 sql += " ," + ((DatabaseTable) tables.get(i)).getName();
00938
00939 spanOnAllTables = new SelectRequest(sql, false, 0, proc
00940 .getLineSeparator());
00941 }
00942 else
00943 spanOnAllTables = new SelectRequest("select * from x", false, 0, proc
00944 .getLineSeparator());
00945
00946
00947
00948
00949 scheduler.scheduleReadRequest(spanOnAllTables);
00950
00951 if (logger.isDebugEnabled())
00952 logger.debug(Translate.get("requestmanager.write.store.procedure",
00953 new String[]{String.valueOf(proc.getId()),
00954 proc.getSQLShortForm(vdb.getSQLShortFormLength())}));
00955
00956
00957
00958
00959
00960
00961 if (resultCache != null)
00962 resultCache.flushCache();
00963
00964 int result;
00965 try
00966 {
00967
00968
00969
00970
00971
00972 result = loadBalancer.execWriteStoredProcedure(proc);
00973
00974
00975
00976
00977
00978 if (recoveryLog != null)
00979 recoveryLog.logRequest(proc, false);
00980
00981 }
00982 catch (Exception failed)
00983 {
00984 scheduler.readCompleted(spanOnAllTables);
00985 String msg = Translate.get("requestmanager.store.procedure.failed",
00986 new String[]{proc.getSQLShortForm(vdb.getSQLShortFormLength()),
00987 failed.getMessage()});
00988 logger.warn(msg);
00989 throw new SQLException(msg);
00990 }
00991
00992
00993 scheduler.readCompleted(spanOnAllTables);
00994
00995 return result;
00996 }
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011 public long begin(String login) throws SQLException
01012 {
01013 try
01014 {
01015 TransactionMarkerMetaData tm = new TransactionMarkerMetaData(0,
01016 beginTimeout, login);
01017
01018
01019 long tid = scheduler.begin(tm);
01020 tm.setTransactionId(tid);
01021
01022 if (logger.isDebugEnabled())
01023 logger.debug(Translate.get("transaction.begin", String.valueOf(tid)));
01024
01025 try
01026 {
01027
01028 loadBalancer.begin(tm);
01029
01030
01031 if (recoveryLog != null)
01032 {
01033 recoveryLog.begin(tm);
01034 }
01035 }
01036 catch (SQLException e)
01037 {
01038 throw e;
01039 }
01040 finally
01041 {
01042
01043 scheduler.beginCompleted(tid);
01044 }
01045
01046 tidLoginTable.put(new Long(tid), tm);
01047 return tid;
01048 }
01049 catch (RuntimeException e)
01050 {
01051 logger.fatal(Translate.get(
01052 "fatal.runtime.exception.requestmanager.begin", e));
01053 throw new SQLException(e.getMessage());
01054 }
01055 }
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066 public void abort(long transactionId) throws SQLException
01067 {
01068 try
01069 {
01070 Long tid = new Long(transactionId);
01071 TransactionMarkerMetaData tm = getTransactionMarker(tid);
01072
01073 if (logger.isDebugEnabled())
01074 logger.debug(Translate.get("transaction.abort", String
01075 .valueOf(transactionId)));
01076
01077 try
01078 {
01079
01080
01081
01082 scheduler.rollback(tm);
01083
01084
01085 if (recoveryLog != null)
01086 {
01087 recoveryLog.abort(tm);
01088 }
01089 }
01090 catch (SQLException e)
01091 {
01092 throw e;
01093 }
01094 finally
01095 {
01096
01097 scheduler.rollbackCompleted(transactionId);
01098
01099 completeTransaction(tid);
01100 }
01101 }
01102 catch (RuntimeException e)
01103 {
01104 logger.fatal(Translate
01105 .get("fatal.runtime.exception.requestmanager.rollback"), e);
01106 throw new SQLException(e.getMessage());
01107 }
01108 }
01109
01110
01111
01112
01113
01114
01115
01116
01117 public TransactionMarkerMetaData getTransactionMarker(Long tid)
01118 throws SQLException
01119 {
01120 TransactionMarkerMetaData tm = (TransactionMarkerMetaData) tidLoginTable
01121 .get(tid);
01122
01123 if (tm == null)
01124 throw new SQLException(Translate.get("transaction.marker.not.found", ""
01125 + tid));
01126
01127 tm.setTimeout(commitTimeout);
01128 return tm;
01129 }
01130
01131
01132
01133
01134
01135
01136 public void completeTransaction(Long tid)
01137 {
01138 tidLoginTable.remove(tid);
01139 }
01140
01141
01142
01143
01144
01145
01146
01147 public void commit(long transactionId) throws SQLException
01148 {
01149 try
01150 {
01151 Long tid = new Long(transactionId);
01152 TransactionMarkerMetaData tm = getTransactionMarker(tid);
01153
01154
01155 scheduler.commit(tm);
01156
01157 if (logger.isDebugEnabled())
01158 logger.debug(Translate.get("transaction.commit", String.valueOf(tid)));
01159
01160 try
01161 {
01162
01163 loadBalancer.commit(tm);
01164
01165
01166 if (resultCache != null)
01167 resultCache.commit(tm.getTransactionId());
01168
01169
01170 if (recoveryLog != null)
01171 recoveryLog.commit(tm);
01172 }
01173 catch (SQLException e)
01174 {
01175 throw e;
01176 }
01177 catch (AllBackendsFailedException e)
01178 {
01179 String msg = "All backends failed to commit transaction "
01180 + transactionId + " (" + e + ")";
01181 logger.error(msg);
01182 throw new SQLException(msg);
01183 }
01184 finally
01185 {
01186
01187 scheduler.commitCompleted(transactionId);
01188
01189 completeTransaction(tid);
01190 }
01191 }
01192 catch (RuntimeException e)
01193 {
01194 logger.fatal(Translate.get(
01195 "fatal.runtime.exception.requestmanager.commit", e));
01196 throw new SQLException(e.getMessage());
01197 }
01198 }
01199
01200
01201
01202
01203
01204
01205
01206 public void rollback(long transactionId) throws SQLException
01207 {
01208 try
01209 {
01210 Long tid = new Long(transactionId);
01211 TransactionMarkerMetaData tm = getTransactionMarker(tid);
01212
01213
01214 scheduler.rollback(tm);
01215
01216 if (logger.isDebugEnabled())
01217 logger.debug(Translate.get("transaction.rollback", String
01218 .valueOf(transactionId)));
01219
01220 try
01221 {
01222
01223 loadBalancer.rollback(tm);
01224
01225
01226 if (this.resultCache != null)
01227 resultCache.rollback(transactionId);
01228
01229
01230 if (recoveryLog != null)
01231 {
01232 recoveryLog.rollback(tm);
01233 }
01234 }
01235 catch (SQLException e)
01236 {
01237 throw e;
01238 }
01239 catch (AllBackendsFailedException e)
01240 {
01241 String msg = Translate.get("requestmanager.rollback.failed.all",
01242 new String[]{String.valueOf(transactionId), e.getMessage()});
01243 logger.error(msg);
01244 throw new SQLException(msg);
01245 }
01246 finally
01247 {
01248
01249 scheduler.rollbackCompleted(transactionId);
01250
01251 completeTransaction(tid);
01252 }
01253 }
01254 catch (RuntimeException e)
01255 {
01256 logger.fatal(Translate
01257 .get("fatal.runtime.exception.requestmanager.rollback"), e);
01258 throw new SQLException(e.getMessage());
01259 }
01260 }
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277 public void enableBackend(DatabaseBackend db) throws SQLException
01278 {
01279 loadBalancer.enableBackend(db, true);
01280 logger.info(Translate.get("backend.state.enabled", db.getName()));
01281 }
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300 public JDBCRecoverThread enableBackendFromCheckpoint(DatabaseBackend db,
01301 String checkpointName) throws SQLException
01302 {
01303
01304 if (recoveryLog == null)
01305 {
01306 String msg = Translate.get(
01307 "recovery.restore.checkpoint.failed.cause.null", checkpointName);
01308 logger.error(msg);
01309 throw new SQLException(msg);
01310 }
01311
01312 if (db.getStateValue() == BackendState.REPLAYING
01313 || db.getStateValue() == BackendState.RECOVERING)
01314 throw new SQLException(Translate.get(
01315 "recovery.restore.backend.state.invalid", db.getName()));
01316
01317 JDBCRecoverThread recoverThread = new JDBCRecoverThread(scheduler,
01318 recoveryLog, db, loadBalancer, checkpointName);
01319
01320
01321
01322
01323 recoverThread.start();
01324 return recoverThread;
01325 }
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337 public void disableBackend(DatabaseBackend db) throws SQLException
01338 {
01339 if (db.isReadEnabled() || db.isWriteEnabled())
01340 {
01341 loadBalancer.disableBackend(db);
01342 logger.info(Translate.get("backend.state.disabled", db.getName()));
01343 }
01344 else
01345 {
01346 throw new SQLException(Translate.get("backend.already.disabled", db
01347 .getName()));
01348 }
01349 }
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362 public void disableBackendForCheckpoint(DatabaseBackend db,
01363 String checkpointName) throws SQLException
01364 {
01365
01366 if (recoveryLog == null)
01367 {
01368 String msg = Translate.get("recovery.store.checkpoint.failed.cause.null",
01369 checkpointName);
01370 logger.error(msg);
01371 throw new SQLException(msg);
01372 }
01373
01374
01375 logger.info(Translate.get("requestmanager.wait.pending.writes"));
01376 scheduler.suspendWrites();
01377
01378
01379 recoveryLog.storeCheckpoint(checkpointName);
01380 logger.info(Translate.get("recovery.checkpoint.stored", checkpointName));
01381
01382
01383 db.setState(BackendState.DISABLING);
01384 logger.info(Translate.get("backend.state.disabling", db.getName()));
01385
01386
01387 logger.info(Translate.get("requestmanager.resume.pending.writes"));
01388 scheduler.resumeWrites();
01389
01390
01391 db.waitForAllTransactionsToComplete();
01392
01393
01394 db.setLastKnownCheckpoint(checkpointName);
01395 loadBalancer.disableBackend(db);
01396 logger.info(Translate.get("backend.state.disabled", db.getName()));
01397 }
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409 public void disableBackendsForCheckpoint(ArrayList backendsArrayList,
01410 String checkpointName) throws SQLException
01411 {
01412
01413 if (recoveryLog == null)
01414 {
01415 String msg = Translate.get("recovery.store.checkpoint.failed.cause.null",
01416 checkpointName);
01417 logger.error(msg);
01418 throw new SQLException(msg);
01419 }
01420
01421
01422 logger.info(Translate.get("requestmanager.wait.pending.writes"));
01423 scheduler.suspendWrites();
01424
01425
01426 recoveryLog.storeCheckpoint(checkpointName);
01427 logger.info(Translate.get("recovery.checkpoint.stored", checkpointName));
01428
01429
01430 DatabaseBackend db;
01431 ArrayList backendList = (ArrayList) backendsArrayList.clone();
01432 for (int i = 0; i < backendList.size(); i++)
01433 {
01434 db = (DatabaseBackend) backendList.get(i);
01435 if (!db.isWriteEnabled())
01436 backendList.remove(i);
01437 }
01438
01439
01440 int size = backendList.size();
01441 for (int i = 0; i < size; i++)
01442 {
01443 db = (DatabaseBackend) backendList.get(i);
01444 db.setState(BackendState.DISABLING);
01445 logger.info(Translate.get("backend.state.disabling", db.getName()));
01446 }
01447
01448
01449 logger.info(Translate.get("requestmanager.resume.pending.writes"));
01450 scheduler.resumeWrites();
01451
01452
01453 for (int i = 0; i < size; i++)
01454 {
01455 db = (DatabaseBackend) backendList.get(i);
01456 db.waitForAllTransactionsToComplete();
01457 }
01458
01459
01460 for (int i = 0; i < size; i++)
01461 {
01462 db = (DatabaseBackend) backendList.get(i);
01463 db.setLastKnownCheckpoint(checkpointName);
01464 loadBalancer.disableBackend(db);
01465 logger.info(Translate.get("backend.state.disabled", db.getName()));
01466 }
01467 }
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482 public void callBackupManager(boolean backup, DatabaseBackend db,
01483 String checkpoint, ArrayList tables, boolean enableAfter,
01484 BackupListener listener) throws Exception
01485 {
01486 if (backup)
01487 backupBackendWithCheckpoint(db, checkpoint, tables, enableAfter, false,
01488 listener);
01489 else
01490 restoreBackendFromBackupCheckpoint(db, checkpoint, false, listener);
01491 }
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505 public void backupBackendWithCheckpoint(DatabaseBackend backend,
01506 String checkpointName, ArrayList tables, boolean enableAfter,
01507 boolean wait4Result, BackupListener listener) throws SQLException
01508 {
01509 if (backend.isReadEnabled())
01510 {
01511 disableBackendForCheckpoint(backend, checkpointName);
01512 logger.info(Translate.get("backend.state.disabled", backend.getName()));
01513 }
01514
01515
01516
01517 try
01518 {
01519 logger.info(Translate.get("controller.backup.octopus.start", backend
01520 .getName()));
01521 backupManager.backup(backend, checkpointName, tables, listener);
01522 if (wait4Result)
01523 backupManager.getResult(backend, 0);
01524 }
01525 catch (OctopusException e)
01526 {
01527 logger.error(Translate.get("controller.backup.octopus.failed"), e);
01528 throw new SQLException(e.getMessage());
01529 }
01530 catch (BackupException be)
01531 {
01532 logger.error(Translate.get("controller.backup.failed"), be);
01533 throw new SQLException(be.getMessage());
01534 }
01535 logger.info(Translate.get("controller.backup.complete", backend.getName()));
01536
01537 if (enableAfter)
01538 {
01539 JDBCRecoverThread thread = enableBackendFromCheckpoint(backend,
01540 checkpointName);
01541 if (wait4Result)
01542 try
01543 {
01544 thread.join();
01545 }
01546 catch (InterruptedException e)
01547 {
01548 logger.error("Recovery thread has been interrupted", e);
01549 }
01550 }
01551
01552 }
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568 public void restoreBackendFromBackupCheckpoint(DatabaseBackend db,
01569 String checkpointName, boolean wait4Result, BackupListener listener)
01570 throws OctopusException, BackupException
01571 {
01572 try
01573 {
01574
01575
01576 if (db.isReadEnabled())
01577 loadBalancer.disableBackend(db);
01578
01579 backupManager.restore(db, checkpointName, null, listener);
01580 if (wait4Result)
01581 backupManager.getResult(db, 0);
01582 }
01583 catch (SQLException e1)
01584 {
01585
01586 throw new BackupException(ExceptionTypes.BACKEND_CANNOT_BE_DISABLED);
01587 }
01588 catch (OctopusException e)
01589 {
01590 logger.error(Translate.get("controller.octopus.recovery.failed"), e);
01591 throw e;
01592 }
01593 catch (BackupException be)
01594 {
01595 logger.error(Translate.get("controller.backup.recovery.failed"), be);
01596 throw be;
01597 }
01598 finally
01599 {
01600 logger.info(Translate
01601 .get("controller.backup.recovery.done", db.getName()));
01602 }
01603 }
01604
01605
01606
01607
01608
01609
01610
01611 public void storeBackendsInfo(String databaseName, ArrayList backends)
01612 {
01613 if (recoveryLog == null)
01614 return;
01615 int size = backends.size();
01616 DatabaseBackend backend;
01617 for (int i = 0; i < size; i++)
01618 {
01619 backend = (DatabaseBackend) backends.get(i);
01620 try
01621 {
01622 recoveryLog.storeBackendRecoveryInfo(databaseName,
01623 new BackendRecoveryInfo(backend.getName(), backend
01624 .getLastKnownCheckpoint(), backend.getStateValue(),
01625 databaseName));
01626 }
01627 catch (SQLException e)
01628 {
01629 logger.error(Translate.get("recovery.store.checkpoint.failed",
01630 new String[]{backend.getName(), e.getMessage()}), e);
01631 }
01632 }
01633 }
01634
01635
01636
01637
01638
01639
01640
01641 public void removeCheckpoint(String checkpointName) throws SQLException
01642 {
01643 recoveryLog.removeCheckpoint(checkpointName);
01644 }
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655 public VirtualDatabase getVirtualDatabase()
01656 {
01657 return vdb;
01658 }
01659
01660
01661
01662
01663
01664
01665
01666
01667 public void setDatabaseSchema(DatabaseSchema schema, boolean isStatic)
01668 {
01669 if (schemaIsStatic)
01670 {
01671 if (isStatic)
01672 {
01673 logger.warn(Translate
01674 .get("requestmanager.schema.replace.static.with.new"));
01675 this.dbs = schema;
01676 }
01677 else
01678 logger.info(Translate.get("requestmanager.schema.ignore.new.dynamic"));
01679 }
01680 else
01681 {
01682 schemaIsStatic = isStatic;
01683 this.dbs = schema;
01684 logger.info(Translate
01685 .get("requestmanager.schema.set.new.virtualdatabase"));
01686 }
01687
01688 if (schedulerParsingranularity != ParsingGranularities.NO_PARSING)
01689 scheduler.setDatabaseSchema(dbs);
01690
01691 if (cacheParsingranularity != ParsingGranularities.NO_PARSING)
01692 resultCache.setDatabaseSchema(dbs);
01693
01694
01695 }
01696
01697
01698
01699
01700
01701
01702 public void mergeDatabaseSchema(DatabaseSchema backendSchema)
01703 {
01704 try
01705 {
01706 if (dbs == null)
01707 setDatabaseSchema(new DatabaseSchema(backendSchema), false);
01708 else
01709 {
01710 dbs.mergeSchema(backendSchema);
01711 logger.info(Translate
01712 .get("requestmanager.schema.virtualdatabase.merged.new"));
01713
01714 if (schedulerParsingranularity != ParsingGranularities.NO_PARSING)
01715 scheduler.mergeDatabaseSchema(dbs);
01716
01717 if (cacheParsingranularity != ParsingGranularities.NO_PARSING)
01718 resultCache.mergeDatabaseSchema(dbs);
01719 }
01720 }
01721 catch (SQLException e)
01722 {
01723 logger.error(Translate.get("requestmanager.schema.merge.failed", e
01724 .getMessage()), e);
01725 }
01726 }
01727
01728
01729
01730
01731
01732
01733 public void setBackupManager(BackupManager currentBackupManager)
01734 {
01735 this.backupManager = currentBackupManager;
01736 }
01737
01738
01739
01740
01741
01742
01743 public BackupManager getBackupManager()
01744 {
01745 return backupManager;
01746 }
01747
01748
01749
01750
01751
01752
01753 public DatabaseSchema getDatabaseSchema()
01754 {
01755 return dbs;
01756 }
01757
01758
01759
01760
01761
01762
01763 public AbstractLoadBalancer getLoadBalancer()
01764 {
01765 return loadBalancer;
01766 }
01767
01768
01769
01770
01771
01772
01773 public void setLoadBalancer(AbstractLoadBalancer loadBalancer)
01774 {
01775 if (this.loadBalancer != null)
01776 throw new RuntimeException(
01777 "It is not possible to dynamically change a load balancer.");
01778 this.loadBalancer = loadBalancer;
01779 if (loadBalancer == null)
01780 return;
01781 loadBalancerParsingranularity = loadBalancer.getParsingGranularity();
01782 if (loadBalancerParsingranularity > requiredGranularity)
01783 requiredGranularity = loadBalancerParsingranularity;
01784
01785 if (MBeanServerManager.isJmxEnabled())
01786 {
01787 try
01788 {
01789 MBeanServerManager.registerMBean(loadBalancer, JmxConstants
01790 .getLoadBalancerObjectName(vdb.getVirtualDatabaseName()));
01791 }
01792 catch (Exception e)
01793 {
01794 logger.error(Translate.get("jmx.failed.register.mbean.loadbalancer"));
01795 }
01796 }
01797
01798 }
01799
01800
01801
01802
01803
01804
01805
01806 public AbstractResultCache getResultCache()
01807 {
01808 return resultCache;
01809 }
01810
01811
01812
01813
01814
01815
01816 public MetadataCache getMetadataCache()
01817 {
01818 return metadataCache;
01819 }
01820
01821
01822
01823
01824
01825
01826 public void setMetadataCache(MetadataCache metadataCache)
01827 {
01828 this.metadataCache = metadataCache;
01829 }
01830
01831
01832
01833
01834
01835
01836 public void setParsingCache(ParsingCache parsingCache)
01837 {
01838 parsingCache.setRequestManager(this);
01839 parsingCache.setGranularity(requiredGranularity);
01840 parsingCache.setCaseSensitiveParsing(isCaseSensitiveParsing);
01841 this.parsingCache = parsingCache;
01842 }
01843
01844
01845
01846
01847
01848
01849 public AbstractRecoveryLog getRecoveryLog()
01850 {
01851 return recoveryLog;
01852 }
01853
01854
01855
01856
01857
01858
01859 public void setRecoveryLog(AbstractRecoveryLog recoveryLog)
01860 {
01861 if (recoveryLog == null)
01862 return;
01863 this.recoveryLog = recoveryLog;
01864 ArrayList backends = vdb.getBackends();
01865 int size = backends.size();
01866 backendStateListener = new BackendStateListener(vdb
01867 .getVirtualDatabaseName(), recoveryLog);
01868 for (int i = 0; i < size; i++)
01869 ((DatabaseBackend) backends.get(i))
01870 .setStateListener(backendStateListener);
01871
01872 if (MBeanServerManager.isJmxEnabled())
01873 {
01874 try
01875 {
01876 MBeanServerManager.registerMBean(recoveryLog, JmxConstants
01877 .getRecoveryLogObjectName(vdb.getVirtualDatabaseName()));
01878 }
01879 catch (Exception e)
01880 {
01881 logger.error(Translate.get("jmx.failed.register.mbean.recoverylog"));
01882 }
01883 }
01884 }
01885
01886
01887
01888
01889
01890
01891 public void setResultCache(AbstractResultCache cache)
01892 {
01893 resultCache = cache;
01894 cacheParsingranularity = cache.getParsingGranularity();
01895 if (cacheParsingranularity > requiredGranularity)
01896 requiredGranularity = cacheParsingranularity;
01897 }
01898
01899
01900
01901
01902
01903
01904
01905 public AbstractScheduler getScheduler()
01906 {
01907 return scheduler;
01908 }
01909
01910
01911
01912
01913
01914
01915 public void setScheduler(AbstractScheduler scheduler)
01916 {
01917 this.scheduler = scheduler;
01918 schedulerParsingranularity = scheduler.getParsingGranularity();
01919 if (schedulerParsingranularity > requiredGranularity)
01920 requiredGranularity = schedulerParsingranularity;
01921 }
01922
01923
01924
01925
01926
01927
01928
01929
01930 public void setCaseSensitiveParsing(boolean isCaseSensitiveParsing)
01931 {
01932 this.isCaseSensitiveParsing = isCaseSensitiveParsing;
01933 if (parsingCache != null)
01934 parsingCache.setCaseSensitiveParsing(isCaseSensitiveParsing);
01935 }
01936
01937
01938
01939
01940 public int getRequiredParsingGranularity()
01941 {
01942 return requiredGranularity;
01943 }
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954 public String getXml()
01955 {
01956 StringBuffer info = new StringBuffer();
01957 info.append("<" + DatabasesXmlTags.ELT_RequestManager + " "
01958 + DatabasesXmlTags.ATT_caseSensitiveParsing + "=\""
01959 + isCaseSensitiveParsing + "\" " + DatabasesXmlTags.ATT_beginTimeout
01960 + "=\"" + beginTimeout / 1000 + "\" "
01961 + DatabasesXmlTags.ATT_commitTimeout + "=\"" + commitTimeout / 1000
01962 + "\" " + DatabasesXmlTags.ATT_rollbackTimeout + "=\""
01963 + rollbackTimeout / 1000 + "\">");
01964 if (scheduler != null)
01965 info.append(scheduler.getXml());
01966
01967 if (metadataCache != null || parsingCache != null || resultCache != null)
01968 {
01969 info.append("<" + DatabasesXmlTags.ELT_RequestCache + ">");
01970 if (metadataCache != null)
01971 info.append(metadataCache.getXml());
01972 if (parsingCache != null)
01973 info.append(parsingCache.getXml());
01974 if (resultCache != null)
01975 info.append(resultCache.getXml());
01976 info.append("</" + DatabasesXmlTags.ELT_RequestCache + ">");
01977 }
01978
01979 if (loadBalancer != null)
01980 info.append(loadBalancer.getXml());
01981 if (recoveryLog != null)
01982 info.append(this.recoveryLog.getXml());
01983 info.append("</" + DatabasesXmlTags.ELT_RequestManager + ">");
01984 return info.toString();
01985 }
01986
01987
01988
01989
01990
01991
01992 public BackendStateListener getBackendStateListener()
01993 {
01994 return backendStateListener;
01995 }
01996
01997
01998
01999
02000
02001
02002 public long getBeginTimeout()
02003 {
02004 return beginTimeout;
02005 }
02006
02007
02008
02009
02010
02011
02012 public void setBeginTimeout(long beginTimeout)
02013 {
02014 this.beginTimeout = beginTimeout;
02015 }
02016
02017
02018
02019
02020
02021
02022 public int getCacheParsingranularity()
02023 {
02024 return cacheParsingranularity;
02025 }
02026
02027
02028
02029
02030
02031
02032 public void setCacheParsingranularity(int cacheParsingranularity)
02033 {
02034 this.cacheParsingranularity = cacheParsingranularity;
02035 }
02036
02037
02038
02039
02040
02041
02042 public long getCommitTimeout()
02043 {
02044 return commitTimeout;
02045 }
02046
02047
02048
02049
02050
02051
02052 public void setCommitTimeout(long commitTimeout)
02053 {
02054 this.commitTimeout = commitTimeout;
02055 }
02056
02057
02058
02059
02060
02061
02062 public int getLoadBalancerParsingranularity()
02063 {
02064 return loadBalancerParsingranularity;
02065 }
02066
02067
02068
02069
02070
02071
02072
02073 public void setLoadBalancerParsingranularity(int loadBalancerParsingranularity)
02074 {
02075 this.loadBalancerParsingranularity = loadBalancerParsingranularity;
02076 }
02077
02078
02079
02080
02081
02082
02083 public int getRequiredGranularity()
02084 {
02085 return requiredGranularity;
02086 }
02087
02088
02089
02090
02091
02092
02093 public void setRequiredGranularity(int requiredGranularity)
02094 {
02095 this.requiredGranularity = requiredGranularity;
02096 }
02097
02098
02099
02100
02101
02102
02103 public long getRollbackTimeout()
02104 {
02105 return rollbackTimeout;
02106 }
02107
02108
02109
02110
02111
02112
02113 public void setRollbackTimeout(long rollbackTimeout)
02114 {
02115 this.rollbackTimeout = rollbackTimeout;
02116 }
02117
02118
02119
02120
02121
02122
02123 public int getSchedulerParsingranularity()
02124 {
02125 return schedulerParsingranularity;
02126 }
02127
02128
02129
02130
02131
02132
02133 public void setSchedulerParsingranularity(int schedulerParsingranularity)
02134 {
02135 this.schedulerParsingranularity = schedulerParsingranularity;
02136 }
02137
02138
02139
02140
02141
02142
02143 public boolean isSchemaIsStatic()
02144 {
02145 return schemaIsStatic;
02146 }
02147
02148
02149
02150
02151
02152
02153 public void setSchemaIsStatic(boolean schemaIsStatic)
02154 {
02155 this.schemaIsStatic = schemaIsStatic;
02156 }
02157
02158
02159
02160
02161
02162
02163 public boolean isCaseSensitiveParsing()
02164 {
02165 return isCaseSensitiveParsing;
02166 }
02167
02168
02169
02170
02171 public String getAssociatedString()
02172 {
02173 return "requestmanager";
02174 }
02175 }