비참조 필드에서 참조 필드로 테이블 데이터를 보관하기 위한 데이터 마이그레이션 프로세스

  • 릴리스 버전: Washingtondc
  • 업데이트 날짜 2024년 02월 01일
  • 읽기4분
  • 데이터 마이그레이션 프로세스는 하위 테이블 및 관련 테이블을 포함하여 기존 보관 테이블에서 데이터를 이동합니다. 이 프로세스를 완료할 때 이해해야 할 특수 스크립트와 메모가 있습니다.

    데이터 마이그레이션 작업(RefCopyJob)

    마이그레이션 프로세스를 통과하는 각 테이블에 대해 참조 RefCopyJob 필드의 sys_id 식별하고 표시 값을 올바른 sys_id로 업데이트합니다. 이 작업은 타임스탬프가 동일한 기록이 10,000개를 초과하지 않는 한 한 번에 10,000개의 기록을 구성합니다. 마이그레이션 진행률은 보관된 타임스탬프에 따라 달라집니다. 이 스크립트는 마이그레이션할 테이블을 결정합니다.
    var tables = GlideDBObjectManager.get().getAllExtensions(current.table);
        for (i = 0; i < tables.size(); i++) {
            var gr = new GlideRecord('sys_archive_ref_migration');
            gr.addQuery('table', 'ar_' + tables.get(i));
            gr.query();
            if (!gr.next()) {
                if (GlideTableDescriptor.isValid('ar_' + tables.get(i))) {
                    var gr2 = new GlideRecord("sys_archive_ref_migration");
                    gr2.initialize();
                    gr2.setValue('rule', current.sys_id);
                    gr2.setValue('table', 'ar_' + tables.get(i));
                    gr2.setValue('reference_migration_progress', 'waiting');
                    gr2.insert();
                }
            }
        }
        //Also get insert related records tables as well
        var map = new GlideRecord('sys_archive');
        map.addQuery('table', current.table);
        map.query();
        if (map.next()) {
            var id = map.getValue('sys_id');
            if (!(id === undefined)) {
                var related = new GlideRecord('sys_archive_related');
                related.addQuery('archive_map', id);
                related.addQuery('action', 'archive');
                related.query();
                while (related.next()) {
                    if (!GlideTableDescriptor.isValid('ar_' + related.getValue('table'))) {
                        gs.log('Related Record table: ' + related.getValue('table') + ' not created yet');
                        continue;
                    }
     
                    var gr3 = new GlideRecord("sys_archive_ref_migration");
                    gr3.initialize();
                    gr3.setValue('rule', current.sys_id);
                    gr3.setValue('table', 'ar_' + related.getValue('table'));
                    gr3.setValue('reference_migration_progress', 'waiting');
                    gr3.insert();
                }
            }
        }

    마이그레이션된 테이블 작업의 sys_dictionary 유형 변경(ArchiveRefJob)

    아카이브 규칙과 연결된 테이블이 완전히 마이그레이션되면 ArchiveRefJob 작업이 실행됩니다. 이 작업은 보관 테이블의 sys_dictionary 유형을 문자열에서 참조로 변경합니다.

    RefCopyJob 및 ArchiveRefJob에 대한 노드 오류 수정

    이러한 작업이 실행되는 동안 노드 오류가 발생하면 데이터 마이그레이션 상태가 부적절한 상태로 남습니다. 실패 RefCopyJob 하면 테이블이 마이그레이션 중 상태로 남을 수 있습니다. sys_archive_ref_migration의 행이 특별한 시간 동안 마이그레이션 상태에 머물러 있는지 확인하여 이 조건을 확인할 수 있습니다(quantify?). 특정 행 상태를 마이그레이션 에서 대기 중 으로 업데이트하고 RefCopyJob 작업이 다시 실행될 때 테이블에서 데이터 마이그레이션을 계속합니다.

    노드가 조기에 종료될 때 ArchiveRefJob 도 실패할 수 있습니다. 테이블에 참조 필드인 필드와 여전히 문자열 유형 필드인 필드가 있는지 확인합니다. 필드 유형을 변경하는 도중에 작업이 종료되었을 수 있습니다. 프로세스를 다시 시작하는 백그라운드 스크립트에서 실행할 트리거 작업을 설정하여 이 문제를 해결할 수 있습니다.
    GlideRecord trigger = new GlideRecord('sys_trigger');
    trigger.initialize();
    trigger.setValue('state', 0);
    trigger.setValue('trigger_type', 0);
    trigger.setValue('next_action', new GlideDateTime());
    trigger.setValue('job_context', 'fcRuleId=' + ruleId);
    trigger.setValue('name', 'Job Reference Migration' + ' Node - ' + new GlideClusterSynchronizer().getSystemID());
    trigger.setValue('trigger_class', 'com.glide.db.auxiliary.job.ArchiveRefJob');
    trigger.insert();