1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
ij> --
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to You under the Apache License, Version 2.0
-- (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- This script tests online backup functionality
-- 1) in a non-idle tranaction.
-- 2) mutiple backup calls on the same connection.
-- 3) when unlogged operations are running in parallel
-- to the backup thread.
connect 'wombat' as c1 ;
ij(C1)> create procedure sleep(t BIGINT) dynamic result sets 0
language java external name 'java.lang.Thread.sleep'
parameter style java;
0 rows inserted/updated/deleted
ij(C1)> create function fileExists(fileName varchar(128))
returns VARCHAR(100) external name
'org.apache.derbyTesting.functionTests.util.FTFileUtil.fileExists'
language java parameter style java;
0 rows inserted/updated/deleted
ij(C1)> create function removeDirectory(fileName varchar(128))
returns VARCHAR(100) external name
'org.apache.derbyTesting.functionTests.util.FTFileUtil.removeDirectory'
language java parameter style java;
0 rows inserted/updated/deleted
ij(C1)> autocommit off;
ij(C1)> create table t1(a int ) ;
0 rows inserted/updated/deleted
ij(C1)> insert into t1 values(1) ;
1 row inserted/updated/deleted
ij(C1)> insert into t1 values(2) ;
1 row inserted/updated/deleted
ij(C1)> commit ;
ij(C1)> -- make sure backup calls are not allowed in a transaction that
-- has executed unlogged operations before the backup calls.
insert into t1 values(3);
1 row inserted/updated/deleted
ij(C1)> create index idx1 on t1(a);
0 rows inserted/updated/deleted
ij(C1)> call SYSCS_UTIL.SYSCS_BACKUP_DATABASE('extinout/mybackup') ;
ERROR XSRSB: Backup cannot be performed in a transaction with uncommitted unlogged operations.
ij(C1)> call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_NOWAIT('extinout/mybackup') ;
ERROR XSRSB: Backup cannot be performed in a transaction with uncommitted unlogged operations.
ij(C1)> call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE(
'extinout/mybackup', 1);
ERROR XSRSB: Backup cannot be performed in a transaction with uncommitted unlogged operations.
ij(C1)> call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT(
'extinout/mybackup', 1);
ERROR XSRSB: Backup cannot be performed in a transaction with uncommitted unlogged operations.
ij(C1)> --backup failures should not rollback/commit the transaction.
select * from t1 ;
A
-----------
1
2
3
ij(C1)> insert into t1 values(4) ;
1 row inserted/updated/deleted
ij(C1)> commit;
ij(C1)> drop index idx1;
0 rows inserted/updated/deleted
ij(C1)> commit;
ij(C1)> --- make sure backup calls can be run one after another.
insert into t1 values(5) ;
1 row inserted/updated/deleted
ij(C1)> call SYSCS_UTIL.SYSCS_BACKUP_DATABASE('extinout/mybackup') ;
0 rows inserted/updated/deleted
ij(C1)> call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_NOWAIT('extinout/mybackup');
0 rows inserted/updated/deleted
ij(C1)> call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE(
'extinout/mybackup', 1);
0 rows inserted/updated/deleted
ij(C1)> call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT(
'extinout/mybackup', 1);
0 rows inserted/updated/deleted
ij(C1)> call SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE(1);
0 rows inserted/updated/deleted
ij(C1)> commit;
ij(C1)> -- make sure backup is not allowed when non-logged
-- operations are pending
connect 'wombat' as c2 ;
ij(C2)> autocommit off ;
ij(C2)> -- index creaton is a non-logged ops, backup should not run
-- until it is committed
create index idx1 on t1(a) ;
0 rows inserted/updated/deleted
ij(C2)> set connection c1 ;
ij(C1)> -- following two backup calls should fail , because they are not waiting
-- for the unlogged index creation in anothere transaction to commit/rollback.
call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_NOWAIT('extinout/mybackup') ;
ERROR XSRSA: Cannot backup the database when unlogged operations are uncommitted. Please commit the transactions with backup blocking operations.
ij(C1)> call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT(
'extinout/mybackup', 1);
ERROR XSRSA: Cannot backup the database when unlogged operations are uncommitted. Please commit the transactions with backup blocking operations.
ij(C1)> set connection c2;
ij(C2)> rollback ;
ij(C2)> -- make sure backup call waits, if wait parameter value is non-zero or
-- the procedures used from before 10.2( old backup procedures wait by
-- default for unlogged operation to finish.)
-- This testing is done by starting backup in a different thread and then
-- wait for few seconds and check if the backup dir is created ?
-- If backup dir is not created , the backup thread is waiting for unlogged
-- op to finih.
-- Note: Not a 100% foolproof approach because checking for backupdir
-- might occur before backup thread gets into action. But I think
-- test will fail atleast on some systems, if backup is not waiting
-- for unlogged ops to complete.
-- case1 : simple database backup with unlogged ops pending.
set connection c2;
ij(C2)> -- index is a non-logged operation
create index idx1 on t1(a) ;
0 rows inserted/updated/deleted
ij(C2)> set connection c1;
ij(C1)> -- make sure backup does not already exists at the backup location.
values removeDirectory('extinout/ulbackup1');
1
----------------------------------------------------------------------------------------------------
true
ij(C1)> values fileExists('extinout/ulbackup1');
1
----------------------------------------------------------------------------------------------------
false
ij(C1)> async bthread1 'call SYSCS_UTIL.SYSCS_BACKUP_DATABASE(
''extinout/ulbackup1'')' ;
ij(C1)> set connection c2;
ij(C2)> -- sleep for a while for the backup thread to
-- really get into the wait state
call sleep(1000);
0 rows inserted/updated/deleted
ij(C2)> -- make sure backup did not really proceed, backup dir should not exist
values fileExists('extinout/ulbackup1');
1
----------------------------------------------------------------------------------------------------
false
ij(C2)> -- rollback the unlogged op for backup to proceed.
rollback;
ij(C2)> set connection c1;
ij(C1)> -- wait for backup thread to finish the work.
wait for bthread1;
0 rows inserted/updated/deleted
ij(C1)> -- check if backup is created.
values fileExists('extinout/ulbackup1');
1
----------------------------------------------------------------------------------------------------
true
ij(C1)> commit;
ij(C1)> -- case2: simple backup call with the default wait for ulogged ops
set connection c2;
ij(C2)> create index idx1 on t1(a) ;
0 rows inserted/updated/deleted
ij(C2)> set connection c1;
ij(C1)> -- make sure backup does not already exists at the backup location.
values removeDirectory('extinout/ulbackup2');
1
----------------------------------------------------------------------------------------------------
true
ij(C1)> values fileExists('extinout/ulbackup2');
1
----------------------------------------------------------------------------------------------------
false
ij(C1)> async bthread1
'call SYSCS_UTIL.SYSCS_BACKUP_DATABASE(''extinout/ulbackup2'')';
ij(C1)> set connection c2;
ij(C2)> -- sleep for a while for the backup thread to
-- really get into the wait state
call sleep(1000);
0 rows inserted/updated/deleted
ij(C2)> -- make sure backup did not really proceed, backup dir should not exist
values fileExists('extinout/ulbackup2');
1
----------------------------------------------------------------------------------------------------
false
ij(C2)> -- rollback the unlogged op for backup to proceed.
rollback;
ij(C2)> set connection c1;
ij(C1)> -- wait for backup thread to finish the work.
wait for bthread1;
0 rows inserted/updated/deleted
ij(C1)> -- check if backup is created.
values fileExists('extinout/ulbackup2');
1
----------------------------------------------------------------------------------------------------
true
ij(C1)> commit;
ij(C1)> --- case 3: log archive backup with with unlogged ops pending.
set connection c2;
ij(C2)> create index idx1 on t1(a) ;
0 rows inserted/updated/deleted
ij(C2)> set connection c1;
ij(C1)> --make sure backup does not already exists at the backup location.
values removeDirectory('extinout/ulbackup3');
1
----------------------------------------------------------------------------------------------------
true
ij(C1)> values fileExists('extinout/ulbackup3');
1
----------------------------------------------------------------------------------------------------
false
ij(C1)> async bthread1
'call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE(
''extinout/ulbackup3'' , 1)' ;
ij(C1)> set connection c2;
ij(C2)> -- sleep for a while for the backup thread to
-- really get into the wait state
call sleep(1000);
0 rows inserted/updated/deleted
ij(C2)> -- make sure backup did not really proceed, backup dir should not exist
values fileExists('extinout/ulbackup3');
1
----------------------------------------------------------------------------------------------------
false
ij(C2)> -- rollback the unlogged op for backup to proceed.
rollback;
ij(C2)> set connection c1;
ij(C1)> -- wait for backup thread to finish the work.
wait for bthread1;
0 rows inserted/updated/deleted
ij(C1)> -- check if backup is created.
values fileExists('extinout/ulbackup3');
1
----------------------------------------------------------------------------------------------------
true
ij(C1)> call SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE(1);
0 rows inserted/updated/deleted
ij(C1)> -- case4 : log archive backup with the defailt wait for unlogged ops.
set connection c2;
ij(C2)> create index idx1 on t1(a) ;
0 rows inserted/updated/deleted
ij(C2)> set connection c1;
ij(C1)> --make sure backup does not already exists at the backup location.
values removeDirectory('extinout/ulbackup4');
1
----------------------------------------------------------------------------------------------------
true
ij(C1)> values fileExists('extinout/ulbackup4');
1
----------------------------------------------------------------------------------------------------
false
ij(C1)> async bthread1
'call SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE(
''extinout/ulbackup4'' , 1)' ;
ij(C1)> set connection c2;
ij(C2)> -- sleep for a while for the backup thread to
-- really get into the wait state
call sleep(1000);
0 rows inserted/updated/deleted
ij(C2)> -- make sure backup did not really proceed, backup dir should not exist
values fileExists('extinout/ulbackup4');
1
----------------------------------------------------------------------------------------------------
false
ij(C2)> -- commit the unlogged op for backup to proceed.
commit;
ij(C2)> set connection c1;
ij(C1)> -- wait for backup thread to finish the work.
wait for bthread1;
0 rows inserted/updated/deleted
ij(C1)> -- check if backup is created.
values fileExists('extinout/ulbackup4');
1
----------------------------------------------------------------------------------------------------
true
ij(C1)> call SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE(1);
0 rows inserted/updated/deleted
ij(C1)>
|