| 95 | } |
| 96 | |
| 97 | IReplicatedSession* getReplicator(thread_db* tdbb) |
| 98 | { |
| 99 | const auto attachment = tdbb->getAttachment(); |
| 100 | |
| 101 | // Disable replication for system attachments |
| 102 | |
| 103 | if (attachment->isSystem()) |
| 104 | return nullptr; |
| 105 | |
| 106 | // Check whether replication is allowed for this session |
| 107 | |
| 108 | if (!(attachment->att_flags & ATT_replicating)) |
| 109 | return nullptr; |
| 110 | |
| 111 | // Check whether replication is configured and enabled for this database |
| 112 | |
| 113 | const auto dbb = tdbb->getDatabase(); |
| 114 | if (!dbb->isReplicating(tdbb)) |
| 115 | { |
| 116 | attachment->att_flags &= ~ATT_replicating; |
| 117 | attachment->att_replicator = nullptr; |
| 118 | return nullptr; |
| 119 | } |
| 120 | |
| 121 | const auto config = dbb->replConfig(); |
| 122 | fb_assert(config); |
| 123 | |
| 124 | // Create a replicator object, unless it already exists |
| 125 | |
| 126 | if (!attachment->att_replicator) |
| 127 | { |
| 128 | if (config->pluginName.empty()) |
| 129 | { |
| 130 | auto& pool = *attachment->att_pool; |
| 131 | const auto manager = dbb->replManager(true); |
| 132 | const auto& guid = dbb->dbb_guid; |
| 133 | const auto& userName = attachment->getUserName(); |
| 134 | |
| 135 | attachment->att_replicator = FB_NEW Replicator(pool, manager, guid, userName); |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | GetPlugins<IReplicatedSession> plugins(IPluginManager::TYPE_REPLICATOR, |
| 140 | config->pluginName.c_str()); |
| 141 | if (!plugins.hasData()) |
| 142 | { |
| 143 | string msg; |
| 144 | msg.printf(NO_PLUGIN_ERROR, config->pluginName.c_str()); |
| 145 | logPrimaryError(dbb->dbb_filename, msg); |
| 146 | |
| 147 | return nullptr; |
| 148 | } |
| 149 | |
| 150 | attachment->att_replicator = plugins.plugin(); |
| 151 | } |
| 152 | |
| 153 | FbLocalStatus status; |
| 154 | const bool replicating = |
no test coverage detected