分布式数据同步

简介: 我们知道Geodatabase的分布式数据库可以在线也可以离线,而在线和离线的接口是不同的,这是因为两者的操作过程不一样,我们看一下两者的区别:                                                                             ...

我们知道Geodatabase的分布式数据库可以在线也可以离线,而在线和离线的接口是不同的,这是因为两者的操作过程不一样,我们看一下两者的区别:


图片                                图片

                                                                                                     在线

图片                         图片
                                                                                                         离线

 

通过这4张图很清楚的说明了原理(其中每一种方式又分为局域网和互联网)

重要的接口:

 GeoDataServer  代表了一个数据库的连接,这句话可能不好理解,但是通过代码,也许会明白:

public IGeoDataServer InitGeoDataServerFromFile(String path)

{

    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.

    IGeoDataServer geoDataServer = new GeoDataServerClass();

    IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;

    geoDataServerInit.InitFromFile(@"C:\arcgis\ArcTutor\DatabaseServers\hazards.gdb");

    return geoDataServer;

}

在离线方式下,我们的数据同步是通过导入,导出,而导入,导出这些方法由此接口提供,看下面的例子:

public void ExportReplicaDataChanges(IGeoDataServer sourceGDS, String replicaName,

    String outputDirectory)

{

    try

    {

        // Set the export options.

        GDSExportOptions gdsExportOptions = new GDSExportOptions();

        gdsExportOptions.ExportFormat = esriGDSExportFormat.esriGDSExportFormatXml;

        gdsExportOptions.Compressed = true;

        gdsExportOptions.BinaryGeometry = false;

 

        // Export the data changes. Note: The replica must be in a Sending Data State.

        IGDSData gdsData = sourceGDS.ExportReplicaDataChanges(replicaName,

            gdsExportOptions, esriGDSTransportType.esriGDSTransportTypeUrl,

            esriExportGenerationsOption.esriExportGenerationsAll, false);

 

        // Force deletion of folder and contents if they exist.

        if (Directory.Exists(outputDirectory))

        {

            Directory.Delete(outputDirectory, true);

        }

 

        // Create the output folder.

        Directory.CreateDirectory(outputDirectory);

 

        // Get the compressed data changes document from the URL to the local output directory.

        if (gdsData.TransportType == esriGDSTransportType.esriGDSTransportTypeUrl)

        {

            string fileName = System.IO.Path.GetFileName(gdsData.URL);

            string outputFileName = System.IO.Path.Combine(outputDirectory, fileName)

                ;

            WebClient wc = new WebClient();

            wc.DownloadFile(gdsData.URL, outputFileName);

            wc.Dispose();

        }

        else

        {

            // The file has been embedded because there is no output directory set on ArcGIS Server.

            Console.WriteLine("Server is not configured with a virtual directory.");

        }

    }

    catch (COMException comExc)

    {

        throw new Exception(String.Format(

            "Exporting data changes errored: {0}, Error Code: {1}", comExc.Message,

            comExc.ErrorCode), comExc);

    }

    catch (Exception exc)

    {

        throw new Exception(String.Format("Exporting data changes errored: {0}",

            exc.Message), exc);

    }

}

而在在线方式下,用ReplicatonAgent接口

ReplicatonAgent 接口就是用来实现在线方式下的同步

public void SynchronizeReplica(IGeoDataServer parentGDS, IGeoDataServer childGDS,

    String replicaName, esriReplicationAgentReconcilePolicy conflictPolicy,

    esriReplicaSynchronizeDirection syncDirection, Boolean columnLevel)

{

    try

    {

        // Iterate through the replicas of the parent geodata server.

        IGPReplicas gpReplicas = parentGDS.Replicas;

        IGPReplica parentReplica = null;

        for (int i = 0; i < gpReplicas.Count; i++)

        {

            // See if the unqualified replica name matches the replicaName parameter.

            IGPReplica currentReplica = gpReplicas.get_Element(i);

            String currentReplicaName = currentReplica.Name;

            int dotIndex = currentReplicaName.LastIndexOf(".") + 1;

            String baseName = currentReplicaName.Substring(dotIndex,

                currentReplicaName.Length - dotIndex);

            if (baseName.ToLower() == replicaName.ToLower())

            {

                parentReplica = currentReplica;

                break;

            }

        }

 

        // Check to see if the parent replica was found.

        if (parentReplica == null)

        {

            throw new ArgumentException(

                "The requested replica could not be found on the parent GDS.");

        }

 

        // Iterate through the replica of the child geodata server.

        gpReplicas = childGDS.Replicas;

        IGPReplica childReplica = null;

        for (int i = 0; i < gpReplicas.Count; i++)

        {

            // See if the unqualified replica name matches the replicaName parameter.

            IGPReplica currentReplica = gpReplicas.get_Element(i);

            String currentReplicaName = currentReplica.Name;

            int dotIndex = currentReplicaName.LastIndexOf(".") + 1;

            String baseName = currentReplicaName.Substring(dotIndex,

                currentReplicaName.Length - dotIndex);

            if (baseName.ToLower() == replicaName.ToLower())

            {

                childReplica = currentReplica;

                break;

            }

        }

 

        // Check to see if the child replica was found.

        if (childReplica == null)

        {

            throw new ArgumentException(

                "The requested replica could not be found on the child GDS.");

        }

 

        // Synchronize the replica.

        IReplicationAgent replicationAgent = new ReplicationAgentClass();

        replicationAgent.SynchronizeReplica(parentGDS, childGDS, parentReplica,

            childReplica, conflictPolicy, syncDirection, columnLevel);

    }

    catch (COMException comExc)

    {

        throw new Exception(String.Format(

            "Create replica errored: {0}, Error Code: {1}", comExc.Message,

            comExc.ErrorCode), comExc);

    }

    catch (Exception exc)

    {

        throw new Exception(String.Format("Create replica errored: {0}", exc.Message)

            , exc);

    }


 

相关文章
|
2月前
|
canal 消息中间件 关系型数据库
【分布式技术专题】「分布式技术架构」MySQL数据同步到Elasticsearch之N种方案解析,实现高效数据同步
【分布式技术专题】「分布式技术架构」MySQL数据同步到Elasticsearch之N种方案解析,实现高效数据同步
173 0
|
canal 存储 消息中间件
史上最全的分布式数据同步中间间canal 之结束篇
前言 文本已收录至我的GitHub仓库,欢迎Star:github.com/bin39232820… 种一棵树最好的时间是十年前,其次是现在
235 0
|
canal 缓存 otter
史上最全的分布式数据同步中间间canal 之入门篇
前言 文本已收录至我的GitHub仓库,欢迎Star:github.com/bin39232820… 种一棵树最好的时间是十年前,其次是现在
411 0
|
11天前
|
NoSQL Redis
redis分布式锁redisson
底层会尝试去加锁,如果加锁失败,会睡眠,自旋加锁,直到获取到锁为止。
15 1
|
8天前
|
消息中间件 NoSQL Java
Redis系列学习文章分享---第六篇(Redis实战篇--Redis分布式锁+实现思路+误删问题+原子性+lua脚本+Redisson功能介绍+可重入锁+WatchDog机制+multiLock)
Redis系列学习文章分享---第六篇(Redis实战篇--Redis分布式锁+实现思路+误删问题+原子性+lua脚本+Redisson功能介绍+可重入锁+WatchDog机制+multiLock)
29 0
|
9天前
|
NoSQL 算法 Java
技术好文:Redis实现分布式锁的7种方案
技术好文:Redis实现分布式锁的7种方案
|
22天前
|
NoSQL 算法 Java
探讨redis分布式锁
探讨redis分布式锁
25 1
|
29天前
|
缓存 NoSQL 安全
玩转Redis!非常强大的Redisson分布式集合,少写60%代码
Redisson是Java的Redis客户端,提供实时数据平台服务,简化了分布式环境下的数据管理。它包含RList、RSet、RMap等分布式集合,支持ConcurrentMap和Set接口,确保线程安全和数据一致性。例如,RMap实现了本地缓存和监听器功能,允许数据监听和本地加速读取。此外,还提供了RSet的排序和去重功能,以及RQueue和RBlockingQueue等队列实现,支持阻塞操作。通过Redisson,开发者能轻松处理分布式系统的数据同步和操作。
|
8天前
|
NoSQL Java Redis
通过Redis 实现分布式锁_利用Jedis 客户端
通过Redis 实现分布式锁_利用Jedis 客户端
|
8天前
|
缓存 NoSQL 数据库
分布式系统面试全集通第一篇(dubbo+redis+zookeeper----分布式+CAP+BASE+分布式事务+分布式锁)
分布式系统面试全集通第一篇(dubbo+redis+zookeeper----分布式+CAP+BASE+分布式事务+分布式锁)
18 0