controller.getServerName() and databaseManager.switchServer

Hi

I have a solution with 3 data sources one of which changes depending on the client at login. I have used the databaseManager.switchServer to change from from one client to the next and this works perfectly

HOWEVER - there are some issues:

  1. The function always returns true even if it has failed to work which seems to be contradictory for a Boolean - if the process fails ie the datasource is incorrect surely it should return false

var requiredDB = ‘org_mailsource’;
var currentDB = ‘org_switch’;
var success = databaseManager.switchServer(currentDB,requiredDB);

(outputs true regardless of wether a server exists or not)

  1. Having worked correctly if you call the controller.getServerName() it returns the original server name configured in the layout properties at the point of creation not the current server.

The problem this presents is not only that the Boolean failed and therefore you have no test to see of the switch worked - you also have the added problem of not being able to switch from the current server to a new one as you cant test to see which is currently configured.

We now have 140 instances of databases that are all ostensibly - the aim being to allow users to admin the data via Servoy and witch them at point of login - any ideas how this can be resolved would be appreciated

Gordon

Hi Gordon,

What version of Servoy are you using ?

ROCLASI:
Hi Gordon,

What version of Servoy are you using ?

Hi

Version 3.5.2

Cheers
Gordon

Gordon,

ad 1)
There are a few checks in the switch-server call, you cannot switch to/from the repository_server and you cannot switch if you have transactions or locks .
In those cases false will be returned.
In all other cases, all calls to server ‘org_switch’ will be rerouted to server ‘org_mailsource’.
An additional check on existence and validity of the target server would be nice but note that the first sql request will fail anyway, so if it didn’t work you will know very soon.

Also note that if switch-server returned true, it (the re-mapping) always worked, all future queries will be executed on the target-server.
If the target-server is not valid, the requests will just fail.

ad 2)
After switch-server, the remapping of the source server to the target server is transparent to the solution, this allows solutions to be designed to the source server work on all target servers without change.
That is why controller.getServerName() returns the original server name.

A possible approach to discover the actual server name is to include a single-record table in your solution that holds the actual server name.
Fill this table with a different value in each db when deploying your solution.

Hope this helps,

Rob

rgansevles:
After switch-server, the remapping of the source server to the target server is transparent to the solution, this allows solutions to be designed to the source server work on all target servers without change.
That is why controller.getServerName() returns the original server name.

A possible approach to discover the actual server name is to include a single-record table in your solution that holds the actual server name.
Fill this table with a different value in each db when deploying your solution.

Hope this helps,

Rob

Hi Rob

Thanks for the reply. I was looking for a complex solution becuase I did not fully appreciate the way you were doing the switch - essentially I was assuming to go from A to B you changed all the references from A to B therefore to go from B to C you needed to be aware of what B was. In fact you switch A to B and then A to C where A is your starting server and B or C are the matched target servers.

This is vital for my solution where I have potentially hundreds of users all using the same application and dialing up different data servers at the same time.

In my test I can get several clients all looking at different data servers via the same solution at the same time which is perfect.

Thanks again for taking the time to reply to my post

Gordon

Hi all,

I know this is a little late to reply, but I just experienced the same thing using servoy 4.1 switchServer will only return false in the cases mentioned and referencing controller.getServerName will always return the original server.

I solved the latter problem using global variables that are always set with the current active servers. I’m using 3 servers simultaneously. However, I was hoping there was a quick and easy way to check if a server exists, a simple boolean method. I can’t find such a method. Is the easiest way to check if a server exists to perform a query on that server and see what you get? That seems awfully cumbersome because you’d have to design the query in such a way to never return false negatives eg. the server exists but the query returned nothing.

And another issue:

Also note that if switch-server returned true, it (the re-mapping) always worked, all future queries will be executed on the target-server.
If the target-server is not valid, the requests will just fail.

When you say all future queries will be executed on the target server, do you mean even if you reference the original server explicitly or through a controller.getServerName() call within the getDataSetByQuery call?

I’ve been using switch server for a month now with good success. And I use controller.getServerName() and currentcontroller.getServerName() in many query calls. I noticed in the debugger that controller.getServerName() evaluates to the original server name, but I believe the query works as expected and I’m just trying to figure out why. Is it safe to say that anything beyond controller.getServerName() that references the original server name will evaluate to the switched target server?

jkipling:
Is it safe to say that anything beyond controller.getServerName() that references the original server name will evaluate to the switched target server?

Yes, all Servoy builtin methods will re-route the queries to the target server.
An exception is the rawSQL plugin, see the sample code for this plugin.

Rob

We just experienced the same issue with getServerName() - we switch servers as well in our application and I was baffled why a call to getServerName() was returning me the original server name and not the one I’m using currently.
We ended up having to set a global variable at the time we do the server switch - it does work but I find this potentially problematic. At this time we only have one database server to worry about but what if we had two? or ten? My point is that there needs to be a way to interrogate a controller at any time and ask it what its current database server is.

In my opinion, the simplest thing that could possibly work is to change the way getServerName() works and have it return the current database server and not the original database server.
If you want to know what the original database server was how about a new method called getOriginalServerName() ?

I smell enhancement request :mrgreen:

Cheers
Mark

markhooper:
In my opinion, the simplest thing that could possibly work is to change the way getServerName() works and have it return the current database server and not the original database server.
If you want to know what the original database server was how about a new method called getOriginalServerName() ?

That would surely break a lot of existing solutions, it would be safer to add a parameter to the getServerName() function like this:

getServerName([boolean getOriginalServerName])

Alternatively you could create a single-record table in your solution where you store the actual server name.
When initializing the solution tables for that actual server just fill this table with the actual server name.

Rob

Yes, that would be a nice workaround ;)