Przeglądaj źródła

支持删除VOTn的信息点历史, 每个VOTn的信息点只保留最后一个当前值

jxing2 6 lat temu
rodzic
commit
345f4eae42

+ 21 - 7
repairInfoTable/src/main/java/com/sagacloud/RepairTable.java

@@ -23,19 +23,19 @@ import java.util.*;
 public class RepairTable {
 
     public static void main(String[] args) {
-        args = new String[]{"-b", "physical_world_v3_226", "-p", "1101080001"};
+        //args = new String[]{"-b", "physical_world_v3_226", "-p", "1101080001"};
         HBaseTable tableInfo = new HBaseTable();
         boolean complete = HBaseTable.getInfo(args, tableInfo);
         if(!complete){
             System.out.println("参数错误, -b 数据库名, -p 项目号(不带Pj)");
             return;
         }
+        System.out.println(tableInfo.getDatabase() + " + " + tableInfo.getDatatable() + " + " + tableInfo.getProjectId());
         ZillionAgent agent = ZillionAgentProvider.GetAgent();
         ResultScanner scanner = null;
         JSONObject criteria = new JSONObject();
-        if(tableInfo.getProjectId() != null && tableInfo.getProjectId().length() > 0){
-            criteria.put("project_id", tableInfo.getProjectId());
-        }
+        generateCriteria(criteria, tableInfo);
+
         ZillionTableSchema schema = agent.container.repositoryMap.get(tableInfo.getDatabase()).GetTable(tableInfo.getDatatable());
         ZillionTableIndex index = HbaseScanIndex.zillionTableIndex(schema, criteria, null);
         try {
@@ -47,6 +47,15 @@ public class RepairTable {
         agent.Stop();
     }
 
+    private static void generateCriteria(JSONObject criteria, HBaseTable tableInfo) {
+        if(tableInfo.isVotn()){
+            criteria.put("obj_type", "VOTn");
+        }
+        if(tableInfo.getProjectId() != null && tableInfo.getProjectId().length() > 0){
+            criteria.put("project_id", tableInfo.getProjectId());
+        }
+    }
+
     private static void fixData(ResultScanner scanner, ZillionTableIndex index, ZillionTableSchema schema, HBaseTable tableInfo) {
         if(scanner == null)
             return;
@@ -78,7 +87,7 @@ public class RepairTable {
                         }
                     }
                 }
-                putToDeleteArr(fixMap, deleteArr);
+                putToDeleteArr(fixMap, deleteArr, tableInfo);
                 if(deleteArr.size() > 2000){
                     ZillionOpUtil.delete(deleteArr, tableInfo);
                     System.out.println("正在修复 " + curProjectId);
@@ -94,7 +103,7 @@ public class RepairTable {
         System.out.println("已完成");
     }
 
-    private static void putToDeleteArr(Map<String, ArrayList<InfosObj>> fixMap, ArrayList<InfosObj> deleteArr) {
+    private static void putToDeleteArr(Map<String, ArrayList<InfosObj>> fixMap, ArrayList<InfosObj> deleteArr, HBaseTable tableInfo) {
         String lastKey = null;
         for(String idKey : fixMap.keySet()){
             lastKey = idKey;
@@ -127,7 +136,12 @@ public class RepairTable {
                 }else{
                     lastValue = single.getObjInfoValue();
                 }
-
+            }
+            if(tableInfo.isVotn()){
+                for(; arr.size() > 1; ){
+                    deleteArr.add(arr.get(0));
+                    arr.remove(0);
+                }
             }
         }
         if(lastKey == null ){

+ 11 - 0
repairInfoTable/src/main/java/com/sagacloud/pojo/HBaseTable.java

@@ -8,6 +8,15 @@ public class HBaseTable {
     private String database;
     private String datatable;
     private String projectId;
+    private boolean votn;   // true的时候, 将虚拟对象的信息点删除到只保留最新的一条
+
+    public boolean isVotn() {
+        return votn;
+    }
+
+    public void setVotn(boolean votn) {
+        this.votn = votn;
+    }
 
     public String getProjectId() {
         return projectId;
@@ -45,6 +54,8 @@ public class HBaseTable {
                     hasDatabaseName = true;
                 }else if(args[i].equals("-p") || args[i].equals("-project")){
                     tableInfo.projectId = args[++i];
+                }else if(args[i].equals("-votn")){
+                    tableInfo.votn = true;
                 }
             }
         }catch (Exception ex){