Skip to content

Commit 4f2fa30

Browse files
author
Roberto E. Garcia
committed
MySql Connector/Net fabric server selection broken when master is faulty (Oracle Bug #21203824).
Added fabric server status (only primary and secondary) when selecting a server (excludes the faulty and spare servers). Added new constructor for MySqlFabricException that accepts an exception as parameter. Reorganized Fabric plugin Enums. Added new validation and resource error message when the specified group is not found in fabric groups list.
1 parent 389ef07 commit 4f2fa30

File tree

6 files changed

+57
-17
lines changed

6 files changed

+57
-17
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
6.9.7
22
- Changed default SSL mode to Preferred in connection string. Now the server connections will be using SSL if server allows it by default but it's possible to override this configuration.
33
- Changed handshake process to use bytes instead of encoded strings.
4+
- Fix for Fabric connections (Oracle Bug #20983968).
5+
- Fix for Fabric plugin: fabric server selection is broken when master is faulty (Oracle Bug #21203824).
46

57

68
6.9.6

Source/Plugins/MySql.Fabric/Enums.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2014, 2015 Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -27,18 +27,18 @@ namespace MySql.Fabric
2727
[Flags]
2828
public enum FabricServerModeEnum
2929
{
30-
Offline = 0x1,
31-
Read_only = 0x2,
32-
Write_only = 0x4,
33-
Read_Write = 0x8
30+
Offline = 0,
31+
Read_only = 1,
32+
Write_only = 2,
33+
Read_Write = 4
3434
}
3535

3636
internal enum FabricServerStatusEnum
3737
{
3838
Faulty = 0,
39-
Spare,
40-
Secondary,
41-
Primary
39+
Spare = 1,
40+
Secondary = 2,
41+
Primary = 3
4242
}
4343

4444
public enum FabricScopeEnum

Source/Plugins/MySql.Fabric/FabricServerGroup.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2014, 2015 Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -54,6 +54,7 @@ internal class FabricServerGroup : ReplicationServerGroup
5454
// always in the format "schema.table"
5555
internal string tableProperty;
5656
internal object keyProperty;
57+
ReplicationServer lastServer = null;
5758

5859

5960
public FabricServerGroup(string name, int retryTime)
@@ -111,14 +112,24 @@ internal protected override ReplicationServer GetServer(bool isMaster, MySqlConn
111112

112113
fabricConnection = new MySqlConnection(servers[0].ConnectionString);
113114
}
115+
bool hasChanged = false;
116+
117+
if (groupIdProperty != settings.FabricGroup) hasChanged = true;
114118
groupIdProperty = settings.FabricGroup;
119+
if (modeProperty != (FabricServerModeEnum?)settings.FabricServerMode) hasChanged = true;
115120
modeProperty = (FabricServerModeEnum?)settings.FabricServerMode;
121+
if (tableProperty != settings.ShardingTable) hasChanged = true;
116122
tableProperty = settings.ShardingTable;
123+
if (keyProperty != settings.ShardingKey) hasChanged = true;
117124
keyProperty = settings.ShardingKey;
118125

119-
GetServerList();
126+
if (hasChanged)
127+
{
128+
GetServerList();
129+
lastServer = GetServer(isMaster);
130+
}
120131

121-
return GetServer(isMaster);
132+
return lastServer;
122133
}
123134

124135
private ReplicationServer GetServerByShard(FabricServerModeEnum mode)
@@ -142,7 +153,12 @@ private ReplicationServer GetServerByShard(FabricServerModeEnum mode)
142153

143154
private ReplicationServer GetServerByGroup(FabricServerModeEnum mode, string groupId)
144155
{
145-
var serversInGroup = FabricGroups[groupId].Servers.Where(i => (i.Mode & mode) != 0).ToList();
156+
if (!FabricGroups.ContainsKey(groupId))
157+
throw new MySqlFabricException(string.Format(Properties.Resources.errorGroupNotFound, groupId));
158+
159+
var serversInGroup = FabricGroups[groupId].Servers.Where(i => (i.Mode & mode) != 0
160+
&& (i.Status == FabricServerStatusEnum.Primary
161+
|| i.Status == FabricServerStatusEnum.Secondary)).ToList();
146162

147163
if (serversInGroup.Count == 0) return null;
148164

@@ -190,7 +206,14 @@ private int ShardKeyCompare(object o1, object o2, FabricShardIndexType shardType
190206

191207
internal protected override void HandleFailover(ReplicationServer server, Exception exception)
192208
{
193-
ExecuteCommand("threat report_error", server.Name);
209+
try
210+
{
211+
ExecuteCommand("threat report_error", server.Name);
212+
}
213+
catch (Exception ex)
214+
{
215+
MySqlTrace.LogError(-1, ex.ToString());
216+
}
194217
GetServerList();
195218
throw exception;
196219
}
@@ -228,10 +251,8 @@ protected DataTable ExecuteCommand(string command, params string[] parameters)
228251
protected void GetServerList()
229252
{
230253
if (lastUpdate.AddSeconds(ttl) > DateTime.Now) return;
231-
//lock (FabricServers)
232254
lock (_lockObject)
233255
{
234-
if (FabricGroups.Count != 0) return;
235256
try
236257
{
237258
GetGroups();
@@ -241,7 +262,7 @@ protected void GetServerList()
241262
catch (Exception ex)
242263
{
243264
MySqlTrace.LogError(-1, ex.ToString());
244-
throw new MySqlFabricException(Properties.Resources.errorConnectFabricServer);
265+
throw new MySqlFabricException(Properties.Resources.errorConnectFabricServer, ex);
245266
}
246267
}
247268
}

Source/Plugins/MySql.Fabric/MySqlFabricException.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2014, 2015 Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -30,5 +30,10 @@ public MySqlFabricException(string message)
3030
: base(message)
3131
{
3232
}
33+
34+
public MySqlFabricException(string message, Exception innerException)
35+
: base(message, innerException)
36+
{
37+
}
3338
}
3439
}

Source/Plugins/MySql.Fabric/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Plugins/MySql.Fabric/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
<data name="errorGroupAndTable" xml:space="preserve">
127127
<value>You have set a group name and a sharding table at the same time. Please set only one.</value>
128128
</data>
129+
<data name="errorGroupNotFound" xml:space="preserve">
130+
<value>Group '{0}' not found.</value>
131+
</data>
129132
<data name="errorNoFabricSettings" xml:space="preserve">
130133
<value>No Fabric settins found.</value>
131134
</data>

0 commit comments

Comments
 (0)