Wednesday, 1 October 2014

OCI ile Veritabanına Bağlanırken Failover/Switchover Durumunda Etkilenmeme ve Load Balancing İşlemi

Fast start Failover aktif edildikte sonra, client server'a bağlanırken 2 tane data source kullanır.


1.cisi SELECT statement’I icin: (JAVA kodu)

String urlString = "jdbc:oracle:oci:@(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=10.204.33.11)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=10.204.33.10)(PORT=1521))
(FAILOVER=true)(LOAD_BALANCE=ON)
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=LBTEST)))";



2.cisi INSERT/UPDATE/DELETE statement’I icin : (JAVA kodu)

String urlString = "jdbc:oracle:oci:@(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=10.204.33.11)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=10.204.33.10)(PORT=1521))
(FAILOVER=true)(LOAD_BALANCE=OFF)
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=LBTELAYS)))";


Normal durumda : Load balance oldugu icin, select her ikisini de ulasmaya calisir. Veritabanı tarafından load balacing işlemi gerçekleştirilir.

Failover ve switchover durumunda trigger’dan (aşağıda) dolayi primary olan database calisiyor olacaktir, ona baglanacak ve islemi gerceklestirecektir.




BEGIN
 DBMS_SERVICE.CREATE_SERVICE('LBTELAYS','LBTELAYS');
 end;
 /

  BEGIN
 DBMS_SERVICE.MODIFY_SERVICE
 ('LBTELAYS',
 FAILOVER_METHOD => 'BASIC',
    FAILOVER_TYPE => 'SELECT',
    FAILOVER_RETRIES => 200,
    FAILOVER_DELAY => 45);
 END;
 /

CREATE TRIGGER CHECK_LBTELAYS_START AFTER STARTUP ON DATABASE
DECLARE
 V_ROLE VARCHAR(30);
 BEGIN
  SELECT DATABASE_ROLE INTO V_ROLE FROM V$DATABASE;
  IF V_ROLE = 'PRIMARY' THEN
   DBMS_SERVICE.START_SERVICE('LBTELAYS');
  ELSE
   DBMS_SERVICE.STOP_SERVICE('LBTELAYS');
  END IF;
 END;
/

 BEGIN
  DBMS_SERVICE.START_SERVICE('LBTELAYS');
 END;
 /

No comments:

Post a Comment