@@ -68,15 +68,15 @@ public class CatalogRecycleBin extends MasterDaemon implements Writable, GsonPos
68
68
// to avoid erase log ahead of drop log
69
69
private static final long minEraseLatency = 10 * 60 * 1000 ; // 10 min
70
70
71
- @ SerializedName (value = "itd" )
72
71
private Map <Long , RecycleDatabaseInfo > idToDatabase ;
73
- @ SerializedName (value = "itt" )
74
72
private Map <Long , RecycleTableInfo > idToTable ;
75
- @ SerializedName (value = "itp" )
76
73
private Map <Long , RecyclePartitionInfo > idToPartition ;
77
- @ SerializedName (value = "itr" )
78
74
private Map <Long , Long > idToRecycleTime ;
79
75
76
+ // for compatible in the future
77
+ @ SerializedName ("u" )
78
+ String unused ;
79
+
80
80
public CatalogRecycleBin () {
81
81
super ("recycle bin" , FeConstants .runningUnitTest ? 10L : DEFAULT_INTERVAL_SECONDS * 1000L );
82
82
idToDatabase = Maps .newHashMap ();
@@ -1287,17 +1287,75 @@ public synchronized Map<Long, Pair<Long, Long>> getDbToRecycleSize() {
1287
1287
// this class is not protected by any lock, will throw ConcurrentModificationException.
1288
1288
@ Override
1289
1289
public synchronized void write (DataOutput out ) throws IOException {
1290
+ out .writeInt (idToDatabase .size ());
1291
+ for (Map .Entry <Long , RecycleDatabaseInfo > entry : idToDatabase .entrySet ()) {
1292
+ out .writeLong (entry .getKey ());
1293
+ entry .getValue ().write (out );
1294
+ }
1295
+ out .writeInt (idToTable .size ());
1296
+ for (Map .Entry <Long , RecycleTableInfo > entry : idToTable .entrySet ()) {
1297
+ out .writeLong (entry .getKey ());
1298
+ entry .getValue ().write (out );
1299
+ }
1300
+ out .writeInt (idToPartition .size ());
1301
+ for (Map .Entry <Long , RecyclePartitionInfo > entry : idToPartition .entrySet ()) {
1302
+ out .writeLong (entry .getKey ());
1303
+ entry .getValue ().write (out );
1304
+ }
1305
+ out .writeInt (idToRecycleTime .size ());
1306
+ for (Map .Entry <Long , Long > entry : idToRecycleTime .entrySet ()) {
1307
+ out .writeLong (entry .getKey ());
1308
+ out .writeLong (entry .getValue ());
1309
+ }
1290
1310
Text .writeString (out , GsonUtils .GSON .toJson (this ));
1291
1311
}
1292
1312
1313
+ public void readFieldsWithGson (DataInput in ) throws IOException {
1314
+ int count = in .readInt ();
1315
+ for (int i = 0 ; i < count ; i ++) {
1316
+ long id = in .readLong ();
1317
+ RecycleDatabaseInfo dbInfo = new RecycleDatabaseInfo ();
1318
+ dbInfo .readFields (in );
1319
+ idToDatabase .put (id , dbInfo );
1320
+ }
1321
+
1322
+ count = in .readInt ();
1323
+ for (int i = 0 ; i < count ; i ++) {
1324
+ long id = in .readLong ();
1325
+ RecycleTableInfo tableInfo = new RecycleTableInfo ();
1326
+ tableInfo = tableInfo .read (in );
1327
+ idToTable .put (id , tableInfo );
1328
+ }
1329
+
1330
+ count = in .readInt ();
1331
+ for (int i = 0 ; i < count ; i ++) {
1332
+ long id = in .readLong ();
1333
+ RecyclePartitionInfo partitionInfo = new RecyclePartitionInfo ();
1334
+ partitionInfo = partitionInfo .read (in );
1335
+ idToPartition .put (id , partitionInfo );
1336
+ }
1337
+
1338
+ count = in .readInt ();
1339
+ for (int i = 0 ; i < count ; i ++) {
1340
+ long id = in .readLong ();
1341
+ long time = in .readLong ();
1342
+ idToRecycleTime .put (id , time );
1343
+ }
1344
+ GsonUtils .GSON .fromJson (Text .readString (in ), CatalogRecycleBin .class );
1345
+ }
1346
+
1293
1347
public static CatalogRecycleBin read (DataInput in ) throws IOException {
1294
- if (Env .getCurrentEnvJournalVersion () >= FeMetaVersion .VERSION_136 ) {
1348
+ if (Env .getCurrentEnvJournalVersion () < FeMetaVersion .VERSION_136 ) {
1349
+ CatalogRecycleBin bin = new CatalogRecycleBin ();
1350
+ bin .readFields (in );
1351
+ return bin ;
1352
+ } else if (Env .getCurrentEnvJournalVersion () < FeMetaVersion .VERSION_139 ) {
1295
1353
return GsonUtils .GSON .fromJson (Text .readString (in ), CatalogRecycleBin .class );
1354
+ } else {
1355
+ CatalogRecycleBin bin = new CatalogRecycleBin ();
1356
+ bin .readFieldsWithGson (in );
1357
+ return bin ;
1296
1358
}
1297
-
1298
- CatalogRecycleBin bin = new CatalogRecycleBin ();
1299
- bin .readFields (in );
1300
- return bin ;
1301
1359
}
1302
1360
1303
1361
@ Override
@@ -1365,12 +1423,12 @@ private void updateDbInfoForLowerVersion() {
1365
1423
}
1366
1424
1367
1425
public class RecycleDatabaseInfo {
1368
- @ SerializedName ("db" )
1369
1426
private Database db ;
1370
- @ SerializedName ("tns" )
1371
1427
private Set <String > tableNames ;
1372
- @ SerializedName ("tis" )
1373
1428
private Set <Long > tableIds ;
1429
+ // for compatibility in the future
1430
+ @ SerializedName ("u" )
1431
+ private String unused ;
1374
1432
1375
1433
public RecycleDatabaseInfo () {
1376
1434
tableNames = Sets .newHashSet ();
@@ -1399,6 +1457,19 @@ public Set<Long> setTableIds(Set<Long> tableIds) {
1399
1457
return this .tableIds = tableIds ;
1400
1458
}
1401
1459
1460
+ public void write (DataOutput out ) throws IOException {
1461
+ db .write (out );
1462
+ out .writeInt (tableNames .size ());
1463
+ for (String tableName : tableNames ) {
1464
+ Text .writeString (out , tableName );
1465
+ }
1466
+ out .writeInt (tableIds .size ());
1467
+ for (Long tableId : tableIds ) {
1468
+ out .writeLong (tableId );
1469
+ }
1470
+ Text .writeString (out , GsonUtils .GSON .toJson (this ));
1471
+ }
1472
+
1402
1473
public void readFields (DataInput in ) throws IOException {
1403
1474
db = Database .read (in );
1404
1475
@@ -1414,6 +1485,9 @@ public void readFields(DataInput in) throws IOException {
1414
1485
tableIds .add (tableId );
1415
1486
}
1416
1487
}
1488
+ if (Env .getCurrentEnvJournalVersion () >= FeMetaVersion .VERSION_139 ) {
1489
+ GsonUtils .GSON .fromJson (Text .readString (in ), RecycleDatabaseInfo .class );
1490
+ }
1417
1491
}
1418
1492
}
1419
1493
@@ -1440,6 +1514,14 @@ public Table getTable() {
1440
1514
return table ;
1441
1515
}
1442
1516
1517
+ public void write (DataOutput out ) throws IOException {
1518
+ Text .writeString (out , GsonUtils .GSON .toJson (this ));
1519
+ }
1520
+
1521
+ public RecycleTableInfo read (DataInput in ) throws IOException {
1522
+ return GsonUtils .GSON .fromJson (Text .readString (in ), RecycleTableInfo .class );
1523
+ }
1524
+
1443
1525
@ Deprecated
1444
1526
public void readFields (DataInput in ) throws IOException {
1445
1527
dbId = in .readLong ();
@@ -1522,6 +1604,14 @@ public boolean isMutable() {
1522
1604
return isMutable ;
1523
1605
}
1524
1606
1607
+ public void write (DataOutput out ) throws IOException {
1608
+ Text .writeString (out , GsonUtils .GSON .toJson (this ));
1609
+ }
1610
+
1611
+ public RecyclePartitionInfo read (DataInput in ) throws IOException {
1612
+ return GsonUtils .GSON .fromJson (Text .readString (in ), RecyclePartitionInfo .class );
1613
+ }
1614
+
1525
1615
public void readFields (DataInput in ) throws IOException {
1526
1616
dbId = in .readLong ();
1527
1617
tableId = in .readLong ();
0 commit comments