While opening a database using LotusScript using failover is simple, opening the same database using the replica id (also with failover) doesn’t seem so… The goals and premises of the below snippets are:
- I would like to open a database, with failover, using the replica id
- I know the database is normally available on server1/Example
- I do not know which other servers are in cluster with server1/Example
Normally opening a database is as simple as:
Dim db As New NotesDatabase("server1/Example", "maildadminis.nsf")
If db.IsOpen Then
Msgbox "Database at " + db.Server + "!!" + db.FilePath + " is open..."
Else
Msgbox "Couldn't open database..."
End If
After replacing one line of code the snippet becomes cluster aware and fails over beautifully to server2/Example if server1/Example is down.
Dim db As New NotesDatabase("", "")
Call db.OpenWithFailover("server1/Example", "maildadminis.nsf")
If db.IsOpen Then
Msgbox "Database at " + db.Server + "!!" + db.FilePath + " is open..."
Else
Msgbox "Couldn't open database..."
End If
Moving along I would like this code to work with a replica id instead of a filename. The obvious choice was to try and open the database using the replica id on server1/Example (which would be down), grab the filename and then open the found filename on server1/Example – now using failover.
Dim exists_in_cluster As Boolean
Dim db As New NotesDatabase("", "")
Call db.OpenByReplicaID("server1/Example", "C125711B0076CBF4")
If Not db.IsOpen Then
'try opening with failover
exists_in_cluster = db.OpenWithFailover(db.Server, db.Filepath)
End If
If exists_in_cluster Then
Msgbox "Database at " + db.Server + "!!" + db.FilePath + " is open..."
Else
Msgbox "Couldn't open database..."
End If
As you might expect this doesn’t work. The database filename isn’t available (after line 3) since the code has no way of translating the replica id to a filename (server1/Example is down – remember).
Another option would be to try and use the NotesDbDirectory class.
Dim dbdir As New NotesDbDirectory("server1/Example")
Dim db As NotesDatabase
Dim path As String
Dim next_db As Boolean
next_db = True
Set db = dbdir.GetFirstDatabase(DATABASE)
While Not (db Is Nothing) And next_db
If db.ReplicaID = "C125711B0076CBF4" Then
path = db.FilePath
next_db = False
Else
Set db = dbdir.GetNextDatabase()
End If
Wend
'try and open the database on server1
Call db.Open("", "")
If Not db.IsOpen Then
'try and open with failover in cluster
Set db = New NotesDatabase("", "")
Call db.OpenWithFailOver("server1/Example", path)
End If
If db.IsOpen Then
Msgbox "Database at " + db.Server + "!!" + db.FilePath + " is open..."
Else
Msgbox "Couldn't open database..."
End If
This doesn’t work either because server1/Example is down hence I’m unable to get a directory listing from the server.
So… What is a LotusScript programmer to do? I could give in and use the Domino Cluster Directory to find the filename for a replica id and then go directly to opening the database using failover. I would however really like to avoid using the Cluster Directory which in my book is a system database which is best left alone. Another option is to use the catalog.nsf to do the same thing.
What really bothers me is that the Domino server and/or the Notes client must already have the functionality since it is used when failing the client over. Why not expose it?
Technorati tag(s): LotusScript, Lotus Notes
Why not do a little “manual” failover. It’s not too bad:
Call db.OpenByReplicaID(“server1/Example”, “C125711B0076CBF4”)
If Not db.IsOpen Then
‘try the next server
call db.OpenByReplicaID(“server2/Example”, “C125711B0076CBF4”)
End If
Make a little loop for your cluster members and off you go.
๐ stw
Well I guess I could, but one of the premises is that I would really like not having to know which servers are in the cluster at any given time. That’s the difficult part… ๐
Eventually a little “pre-failover maintenance” would do the trick:
In the postopen or on a scheduled agent put a little code that captures the cluster members in a profile field. This field could be used to get the list of servers to try. If you then store the “GEO” Location of the client in the Notes.ini and the “GEO” location of the servers there you could even come up with some sequence algorythm if you have a distributed cluster. GEO is in quotes because your map would need to be distorted by bandwith (a 100 mile distant server on a T1 is for sure a better choice than a 100m away with dialup)
My 2c
Yeah it seems like there is no way around knowing which servers are in the cluster or doing it lazily, that is going to the Cluster Directory or similar in case of a cluster server being down. It would just have really nice it the operation was as transparent as OpenDatabaseWithFailover.