11package syncer .transmission .task ;
22
33import java .io .IOException ;
4-
54import lombok .extern .slf4j .Slf4j ;
65import syncer .jedis .Protocol ;
76import syncer .replica .config .RedisURI ;
2120import syncer .replica .util .SyncTypeUtils ;
2221import syncer .replica .util .TaskRunTypeEnum ;
2322import syncer .replica .util .strings .Strings ;
23+ import syncer .replica .util .type .ExpiredType ;
2424import syncer .transmission .checkpoint .breakpoint .BreakPoint ;
2525import syncer .transmission .client .RedisClient ;
2626import syncer .transmission .client .RedisClientFactory ;
@@ -208,11 +208,25 @@ public void onEvent(Replication replicator, Event event) {
208208 //全量命令 RESTORE
209209 if (event instanceof DumpKeyValuePairEvent ) {
210210 DumpKeyValuePairEvent valueDump = (DumpKeyValuePairEvent ) event ;
211- Long ms = valueDump .getExpiredMs ();
212211 RedisDB vdb = valueDump .getDb ();
213212 Long dbNum = vdb .getCurrentDbNumber ();
214213 db = dbNum .intValue ();
215- long ttl = (ms == null || ms < 0 ) ? 0 : ms ;
214+ long ttlMs = 0 ;
215+
216+ // expiryTime 是到期时间,不是剩余过期时间
217+ if (!ExpiredType .NONE .equals (valueDump .getExpiredType ())) {
218+ long expiryTimeMs = 0L ;
219+ if (ExpiredType .SECOND .equals (valueDump .getExpiredType ())) {
220+ expiryTimeMs = valueDump .getExpiredSeconds () * 1000L ;
221+ } else if (ExpiredType .MS .equals (valueDump .getExpiredType ())) {
222+ expiryTimeMs = valueDump .getExpiredMs ();
223+ }
224+ ttlMs = expiryTimeMs - System .currentTimeMillis ();
225+ if (ttlMs <= 0 ) {
226+ log .debug ("restore... ignore expired key [{}]" , Strings .byteToString (valueDump .getKey ()));
227+ return ;
228+ }
229+ }
216230 String rdbDumpMd5 = circle .getRdbDumpMd5 (valueDump , sourceRedisName , 3.0 );
217231 String dumpKey = Strings .byteToString (valueDump .getKey ());
218232 String [] data = new String [] { rdbDumpMd5 , "1" , "1" };
@@ -224,7 +238,7 @@ public void onEvent(Replication replicator, Event event) {
224238 log .error ("restore key:[" + dumpKey + "] fail" , e );
225239 e .printStackTrace ();
226240 }
227- client .restoreReplace (dbNum , valueDump .getKey (), ttl , valueDump .getValue (), true );
241+ client .restoreReplace (dbNum , valueDump .getKey (), ttlMs , valueDump .getValue (), true );
228242 }
229243
230244 // 更新offset
0 commit comments