Skip to content

Commit 81642f3

Browse files
committed
Address review comments
1 parent 1f4b940 commit 81642f3

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotTTLExpiredException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
@InterfaceAudience.Public
2929
public class SnapshotTTLExpiredException extends HBaseSnapshotException {
3030
/**
31+
* Failure when the ttl for snapshot has already expired.
3132
* @param message the full description of the failure
3233
*/
3334
public SnapshotTTLExpiredException(String message) {
3435
super(message);
3536
}
3637

3738
/**
38-
* @param snapshotDescription expected snapshot to find
39+
* Failure when the ttl for snapshot has already expired.
40+
* @param snapshotDescription snapshot that was attempted
3941
*/
4042
public SnapshotTTLExpiredException(SnapshotDescription snapshotDescription) {
4143
super("TTL for snapshot '" + snapshotDescription.getName() + "' has already expired.",

hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotDescriptionUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,12 @@ public ListMultimap<String, UserPermission> run() throws Exception {
470470
* Method to check whether TTL has expired for specified snapshot creation time and snapshot ttl.
471471
* NOTE: For backward compatibility (after the patch deployment on HMaster), any snapshot with ttl
472472
* 0 is to be considered as snapshot to keep FOREVER. Default ttl value specified by
473-
* {@HConstants.DEFAULT_SNAPSHOT_TTL}
473+
* {@link HConstants#DEFAULT_SNAPSHOT_TTL}
474474
* @return true if ttl has expired, or, false, otherwise
475475
*/
476476
public static boolean isExpiredSnapshot(long snapshotTtl, long snapshotCreatedTime,
477477
long currentTime) {
478-
return snapshotCreatedTime > 0 && snapshotTtl > 0
478+
return snapshotCreatedTime > 0 && snapshotTtl > HConstants.DEFAULT_SNAPSHOT_TTL
479479
&& snapshotTtl < TimeUnit.MILLISECONDS.toSeconds(Long.MAX_VALUE)
480480
&& (snapshotCreatedTime + TimeUnit.SECONDS.toMillis(snapshotTtl)) < currentTime;
481481
}

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotWithTTLFromClient.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package org.apache.hadoop.hbase.client;
1919

2020
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
22+
import static org.junit.Assert.assertTrue;
2123
import static org.junit.Assert.fail;
2224

2325
import java.io.IOException;
@@ -115,7 +117,7 @@ public void testRestoreSnapshotWithTTLSuccess() throws Exception {
115117
String snapshotName = "nonExpiredTTLRestoreSnapshotTest";
116118

117119
// table should exist
118-
assertEquals(true, UTIL.getAdmin().tableExists(TABLE_NAME));
120+
assertTrue(UTIL.getAdmin().tableExists(TABLE_NAME));
119121

120122
// create snapshot fo given table with specified ttl
121123
createSnapshotWithTTL(TABLE_NAME, snapshotName, CHORE_INTERVAL_SECS * 2);
@@ -124,21 +126,21 @@ public void testRestoreSnapshotWithTTLSuccess() throws Exception {
124126
// Disable and drop table
125127
admin.disableTable(TABLE_NAME);
126128
admin.deleteTable(TABLE_NAME);
127-
assertEquals(false, UTIL.getAdmin().tableExists(TABLE_NAME));
129+
assertFalse(UTIL.getAdmin().tableExists(TABLE_NAME));
128130

129131
// restore snapshot
130132
admin.restoreSnapshot(snapshotName);
131133

132134
// table should be created
133-
assertEquals(true, UTIL.getAdmin().tableExists(TABLE_NAME));
135+
assertTrue(UTIL.getAdmin().tableExists(TABLE_NAME));
134136
}
135137

136138
@Test
137139
public void testRestoreSnapshotFailsDueToTTLExpired() throws Exception {
138140
String snapshotName = "expiredTTLRestoreSnapshotTest";
139141

140142
// table should exist
141-
assertEquals(true, UTIL.getAdmin().tableExists(TABLE_NAME));
143+
assertTrue(UTIL.getAdmin().tableExists(TABLE_NAME));
142144

143145
// create snapshot fo given table with specified ttl
144146
createSnapshotWithTTL(TABLE_NAME, snapshotName, 1);
@@ -147,7 +149,7 @@ public void testRestoreSnapshotFailsDueToTTLExpired() throws Exception {
147149
// Disable and drop table
148150
admin.disableTable(TABLE_NAME);
149151
admin.deleteTable(TABLE_NAME);
150-
assertEquals(false, UTIL.getAdmin().tableExists(TABLE_NAME));
152+
assertFalse(UTIL.getAdmin().tableExists(TABLE_NAME));
151153

152154
// Sleep so that TTL may expire
153155
Threads.sleep(2000);
@@ -161,15 +163,15 @@ public void testRestoreSnapshotFailsDueToTTLExpired() throws Exception {
161163
}
162164

163165
// table should not be created
164-
assertEquals(false, UTIL.getAdmin().tableExists(TABLE_NAME));
166+
assertFalse(UTIL.getAdmin().tableExists(TABLE_NAME));
165167
}
166168

167169
@Test
168170
public void testCloneSnapshotWithTTLSuccess() throws Exception {
169171
String snapshotName = "nonExpiredTTLCloneSnapshotTest";
170172

171173
// table should exist
172-
assertEquals(true, UTIL.getAdmin().tableExists(TABLE_NAME));
174+
assertTrue(UTIL.getAdmin().tableExists(TABLE_NAME));
173175

174176
// create snapshot fo given table with specified ttl
175177
createSnapshotWithTTL(TABLE_NAME, snapshotName, CHORE_INTERVAL_SECS * 2);
@@ -179,21 +181,21 @@ public void testCloneSnapshotWithTTLSuccess() throws Exception {
179181
admin.cloneSnapshot(snapshotName, CLONED_TABLE_NAME);
180182

181183
// table should be created
182-
assertEquals(true, UTIL.getAdmin().tableExists(CLONED_TABLE_NAME));
184+
assertTrue(UTIL.getAdmin().tableExists(CLONED_TABLE_NAME));
183185
}
184186

185187
@Test
186188
public void testCloneSnapshotFailsDueToTTLExpired() throws Exception {
187189
String snapshotName = "expiredTTLCloneSnapshotTest";
188190

189191
// table should exist
190-
assertEquals(true, UTIL.getAdmin().tableExists(TABLE_NAME));
192+
assertTrue(UTIL.getAdmin().tableExists(TABLE_NAME));
191193

192194
// create snapshot fo given table with specified ttl
193195
createSnapshotWithTTL(TABLE_NAME, snapshotName, 1);
194196
Admin admin = UTIL.getAdmin();
195197

196-
assertEquals(true, UTIL.getAdmin().tableExists(TABLE_NAME));
198+
assertTrue(UTIL.getAdmin().tableExists(TABLE_NAME));
197199

198200
// Sleep so that TTL may expire
199201
Threads.sleep(2000);
@@ -207,7 +209,7 @@ public void testCloneSnapshotFailsDueToTTLExpired() throws Exception {
207209
}
208210

209211
// table should not be created
210-
assertEquals(false, UTIL.getAdmin().tableExists(CLONED_TABLE_NAME));
212+
assertFalse(UTIL.getAdmin().tableExists(CLONED_TABLE_NAME));
211213
}
212214

213215
private void createSnapshotWithTTL(TableName tableName, final String snapshotName,

0 commit comments

Comments
 (0)