@celerispay/hazelcast-client 3.12.5 → 3.12.7-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +111 -87
- package/CHANGES_UNCOMMITTED.md +53 -0
- package/FAILOVER_FIXES.md +148 -230
- package/FAULT_TOLERANCE_IMPROVEMENTS.md +208 -0
- package/HAZELCAST_CLIENT_EVOLUTION.md +402 -0
- package/QUICK_START.md +184 -95
- package/RELEASE_SUMMARY.md +227 -147
- package/lib/HeartbeatService.js +11 -2
- package/lib/PartitionService.d.ts +14 -0
- package/lib/PartitionService.js +32 -9
- package/lib/invocation/ClientConnection.d.ts +14 -0
- package/lib/invocation/ClientConnection.js +95 -1
- package/lib/invocation/ClientConnectionManager.d.ts +99 -0
- package/lib/invocation/ClientConnectionManager.js +394 -10
- package/lib/invocation/ClusterService.d.ts +98 -5
- package/lib/invocation/ClusterService.js +541 -17
- package/lib/invocation/ConnectionAuthenticator.d.ts +11 -0
- package/lib/invocation/ConnectionAuthenticator.js +85 -12
- package/lib/invocation/CredentialPreservationService.d.ts +141 -0
- package/lib/invocation/CredentialPreservationService.js +377 -0
- package/lib/invocation/HazelcastFailoverManager.d.ts +102 -0
- package/lib/invocation/HazelcastFailoverManager.js +285 -0
- package/lib/invocation/InvocationService.js +8 -0
- package/lib/nearcache/StaleReadDetectorImpl.js +31 -4
- package/lib/proxy/ProxyManager.js +25 -4
- package/package.json +20 -28
|
@@ -10,5 +10,16 @@ export declare class ConnectionAuthenticator {
|
|
|
10
10
|
private logger;
|
|
11
11
|
constructor(connection: ClientConnection, client: HazelcastClient);
|
|
12
12
|
authenticate(asOwner: boolean): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Gets a human-readable description of authentication status
|
|
15
|
+
*/
|
|
16
|
+
private getStatusDescription(status);
|
|
17
|
+
/**
|
|
18
|
+
* Creates credentials with optional restoration from preservation service
|
|
19
|
+
* @param asOwner Whether this is an owner connection
|
|
20
|
+
* @param preservedCredentials Optional preserved credentials to use
|
|
21
|
+
* @returns The credentials message
|
|
22
|
+
*/
|
|
23
|
+
createCredentialsWithRestoration(asOwner: boolean, preservedCredentials?: any): ClientMessage;
|
|
13
24
|
createCredentials(asOwner: boolean): ClientMessage;
|
|
14
25
|
}
|
|
@@ -34,53 +34,126 @@ var ConnectionAuthenticator = /** @class */ (function () {
|
|
|
34
34
|
}
|
|
35
35
|
ConnectionAuthenticator.prototype.authenticate = function (asOwner) {
|
|
36
36
|
var _this = this;
|
|
37
|
+
var addressStr = this.connection.getAddress().toString();
|
|
38
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDD10 Starting authentication for " + addressStr + " (asOwner=" + asOwner + ")");
|
|
37
39
|
var credentials = this.createCredentials(asOwner);
|
|
40
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDCE4 Sending authentication request to " + addressStr + "...");
|
|
38
41
|
return this.client.getInvocationService()
|
|
39
42
|
.invokeOnConnection(this.connection, credentials)
|
|
40
43
|
.then(function (msg) {
|
|
44
|
+
_this.logger.info('ConnectionAuthenticator', "\uD83D\uDCE5 Received authentication response from " + addressStr);
|
|
41
45
|
var authResponse = ClientAuthenticationCodec_1.ClientAuthenticationCodec.decodeResponse(msg);
|
|
46
|
+
_this.logger.info('ConnectionAuthenticator', "\uD83D\uDD0D Authentication response for " + addressStr + ":");
|
|
47
|
+
_this.logger.info('ConnectionAuthenticator', " - Status: " + authResponse.status + " (" + _this.getStatusDescription(authResponse.status) + ")");
|
|
48
|
+
_this.logger.info('ConnectionAuthenticator', " - Server UUID: " + (authResponse.uuid || 'NOT PROVIDED'));
|
|
49
|
+
_this.logger.info('ConnectionAuthenticator', " - Server Owner UUID: " + (authResponse.ownerUuid || 'NOT PROVIDED'));
|
|
50
|
+
_this.logger.info('ConnectionAuthenticator', " - Server Address: " + (authResponse.address ? authResponse.address.toString() : 'NOT PROVIDED'));
|
|
51
|
+
_this.logger.info('ConnectionAuthenticator', " - Server Version: " + (authResponse.serverHazelcastVersion || 'NOT PROVIDED'));
|
|
42
52
|
switch (authResponse.status) {
|
|
43
53
|
case 0 /* AUTHENTICATED */:
|
|
54
|
+
_this.logger.info('ConnectionAuthenticator', "\u2705 Authentication SUCCESSFUL for " + addressStr);
|
|
44
55
|
_this.connection.setAddress(authResponse.address);
|
|
45
56
|
_this.connection.setConnectedServerVersion(authResponse.serverHazelcastVersion);
|
|
46
57
|
if (asOwner) {
|
|
58
|
+
var oldUuid = _this.clusterService.uuid;
|
|
59
|
+
var oldOwnerUuid = _this.clusterService.ownerUuid;
|
|
47
60
|
_this.clusterService.uuid = authResponse.uuid;
|
|
48
61
|
_this.clusterService.ownerUuid = authResponse.ownerUuid;
|
|
62
|
+
_this.logger.info('ConnectionAuthenticator', "\uD83D\uDD04 Updated cluster service for " + addressStr + ":");
|
|
63
|
+
_this.logger.info('ConnectionAuthenticator', " - UUID: " + (oldUuid || 'NOT SET') + " \u2192 " + authResponse.uuid);
|
|
64
|
+
_this.logger.info('ConnectionAuthenticator', " - Owner UUID: " + (oldOwnerUuid || 'NOT SET') + " \u2192 " + authResponse.ownerUuid);
|
|
49
65
|
}
|
|
50
|
-
_this.logger.info('ConnectionAuthenticator',
|
|
51
|
-
_this.connection.getAddress().toString() + ' authenticated');
|
|
66
|
+
_this.logger.info('ConnectionAuthenticator', "\u2705 Connection to " + addressStr + " authenticated successfully");
|
|
52
67
|
break;
|
|
53
68
|
case 1 /* CREDENTIALS_FAILED */:
|
|
54
|
-
_this.logger.error('ConnectionAuthenticator',
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
_this.logger.error('ConnectionAuthenticator', "\u274C Authentication FAILED for " + addressStr + ": Invalid Credentials");
|
|
70
|
+
_this.logger.error('ConnectionAuthenticator', " - Server rejected our credentials");
|
|
71
|
+
_this.logger.error('ConnectionAuthenticator', " - Check if UUIDs and group credentials are correct");
|
|
72
|
+
throw new Error('Invalid Credentials, could not authenticate connection to ' + addressStr);
|
|
57
73
|
case 2 /* SERIALIZATION_VERSION_MISMATCH */:
|
|
58
|
-
_this.logger.error('ConnectionAuthenticator',
|
|
59
|
-
throw new Error('Serialization version mismatch, could not authenticate connection to ' +
|
|
60
|
-
_this.connection.getAddress().toString());
|
|
74
|
+
_this.logger.error('ConnectionAuthenticator', "\u274C Authentication FAILED for " + addressStr + ": Serialization version mismatch");
|
|
75
|
+
throw new Error('Serialization version mismatch, could not authenticate connection to ' + addressStr);
|
|
61
76
|
default:
|
|
62
|
-
_this.logger.error('ConnectionAuthenticator',
|
|
63
|
-
+ authResponse.status);
|
|
77
|
+
_this.logger.error('ConnectionAuthenticator', "\u274C Authentication FAILED for " + addressStr + ": Unknown status " + authResponse.status);
|
|
64
78
|
throw new HazelcastError_1.AuthenticationError('Unknown authentication status: ' + authResponse.status +
|
|
65
|
-
' , could not authenticate connection to ' +
|
|
66
|
-
_this.connection.getAddress().toString());
|
|
79
|
+
' , could not authenticate connection to ' + addressStr);
|
|
67
80
|
}
|
|
81
|
+
})
|
|
82
|
+
.catch(function (error) {
|
|
83
|
+
_this.logger.error('ConnectionAuthenticator', "\uD83D\uDCA5 Authentication ERROR for " + addressStr + ": " + error.message);
|
|
84
|
+
throw error;
|
|
68
85
|
});
|
|
69
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* Gets a human-readable description of authentication status
|
|
89
|
+
*/
|
|
90
|
+
ConnectionAuthenticator.prototype.getStatusDescription = function (status) {
|
|
91
|
+
switch (status) {
|
|
92
|
+
case 0 /* AUTHENTICATED */: return 'AUTHENTICATED';
|
|
93
|
+
case 1 /* CREDENTIALS_FAILED */: return 'CREDENTIALS_FAILED';
|
|
94
|
+
case 2 /* SERIALIZATION_VERSION_MISMATCH */: return 'SERIALIZATION_VERSION_MISMATCH';
|
|
95
|
+
default: return "UNKNOWN_STATUS_" + status;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Creates credentials with optional restoration from preservation service
|
|
100
|
+
* @param asOwner Whether this is an owner connection
|
|
101
|
+
* @param preservedCredentials Optional preserved credentials to use
|
|
102
|
+
* @returns The credentials message
|
|
103
|
+
*/
|
|
104
|
+
ConnectionAuthenticator.prototype.createCredentialsWithRestoration = function (asOwner, preservedCredentials) {
|
|
105
|
+
if (preservedCredentials && preservedCredentials.uuid && preservedCredentials.ownerUuid) {
|
|
106
|
+
this.logger.debug('ConnectionAuthenticator', "Using preserved credentials: uuid=" + preservedCredentials.uuid + ", ownerUuid=" + preservedCredentials.ownerUuid);
|
|
107
|
+
// Use preserved credentials instead of current cluster state
|
|
108
|
+
var groupConfig = this.client.getConfig().groupConfig;
|
|
109
|
+
var customCredentials = this.client.getConfig().customCredentials;
|
|
110
|
+
var clientMessage = void 0;
|
|
111
|
+
var clientVersion = BuildInfo_1.BuildInfo.getClientVersion();
|
|
112
|
+
if (customCredentials != null) {
|
|
113
|
+
var credentialsPayload = this.client.getSerializationService().toData(customCredentials);
|
|
114
|
+
clientMessage = ClientAuthenticationCustomCodec_1.ClientAuthenticationCustomCodec.encodeRequest(credentialsPayload, preservedCredentials.uuid, preservedCredentials.ownerUuid, asOwner, 'NJS', 1, clientVersion);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
clientMessage = ClientAuthenticationCodec_1.ClientAuthenticationCodec.encodeRequest(preservedCredentials.groupName, preservedCredentials.groupPassword, preservedCredentials.uuid, preservedCredentials.ownerUuid, asOwner, 'NJS', 1, clientVersion);
|
|
118
|
+
}
|
|
119
|
+
return clientMessage;
|
|
120
|
+
}
|
|
121
|
+
// Fall back to normal credential creation
|
|
122
|
+
return this.createCredentials(asOwner);
|
|
123
|
+
};
|
|
70
124
|
ConnectionAuthenticator.prototype.createCredentials = function (asOwner) {
|
|
71
125
|
var groupConfig = this.client.getConfig().groupConfig;
|
|
72
126
|
var uuid = this.clusterService.uuid;
|
|
73
127
|
var ownerUuid = this.clusterService.ownerUuid;
|
|
74
128
|
var customCredentials = this.client.getConfig().customCredentials;
|
|
129
|
+
// LOG EXACTLY WHAT CREDENTIALS WE'RE SENDING
|
|
130
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDD10 Creating authentication credentials for " + this.connection.getAddress().toString() + ":");
|
|
131
|
+
this.logger.info('ConnectionAuthenticator', " - As Owner: " + asOwner);
|
|
132
|
+
this.logger.info('ConnectionAuthenticator', " - UUID: " + (uuid || 'NOT SET'));
|
|
133
|
+
this.logger.info('ConnectionAuthenticator', " - Owner UUID: " + (ownerUuid || 'NOT SET'));
|
|
134
|
+
this.logger.info('ConnectionAuthenticator', " - Group Name: " + (groupConfig.name || 'NOT SET'));
|
|
135
|
+
this.logger.info('ConnectionAuthenticator', " - Group Password: " + (groupConfig.password ? '***SET***' : 'NOT SET'));
|
|
136
|
+
this.logger.info('ConnectionAuthenticator', " - Custom Credentials: " + (customCredentials ? 'YES' : 'NO'));
|
|
137
|
+
this.logger.info('ConnectionAuthenticator', " - Client Version: " + BuildInfo_1.BuildInfo.getClientVersion());
|
|
75
138
|
var clientMessage;
|
|
76
139
|
var clientVersion = BuildInfo_1.BuildInfo.getClientVersion();
|
|
77
140
|
if (customCredentials != null) {
|
|
78
141
|
var credentialsPayload = this.client.getSerializationService().toData(customCredentials);
|
|
142
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDCE4 Sending CUSTOM authentication request with:");
|
|
143
|
+
this.logger.info('ConnectionAuthenticator', " - Custom Credentials: " + typeof credentialsPayload);
|
|
144
|
+
this.logger.info('ConnectionAuthenticator', " - UUID: " + (uuid || 'NOT SET'));
|
|
145
|
+
this.logger.info('ConnectionAuthenticator', " - Owner UUID: " + (ownerUuid || 'NOT SET'));
|
|
79
146
|
clientMessage = ClientAuthenticationCustomCodec_1.ClientAuthenticationCustomCodec.encodeRequest(credentialsPayload, uuid, ownerUuid, asOwner, 'NJS', 1, clientVersion);
|
|
80
147
|
}
|
|
81
148
|
else {
|
|
149
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDCE4 Sending STANDARD authentication request with:");
|
|
150
|
+
this.logger.info('ConnectionAuthenticator', " - Group Name: " + (groupConfig.name || 'NOT SET'));
|
|
151
|
+
this.logger.info('ConnectionAuthenticator', " - Group Password: " + (groupConfig.password ? '***SET***' : 'NOT SET'));
|
|
152
|
+
this.logger.info('ConnectionAuthenticator', " - UUID: " + (uuid || 'NOT SET'));
|
|
153
|
+
this.logger.info('ConnectionAuthenticator', " - Owner UUID: " + (ownerUuid || 'NOT SET'));
|
|
82
154
|
clientMessage = ClientAuthenticationCodec_1.ClientAuthenticationCodec.encodeRequest(groupConfig.name, groupConfig.password, uuid, ownerUuid, asOwner, 'NJS', 1, clientVersion);
|
|
83
155
|
}
|
|
156
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDCCB Final authentication message created and ready to send");
|
|
84
157
|
return clientMessage;
|
|
85
158
|
};
|
|
86
159
|
return ConnectionAuthenticator;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ILogger } from '../logging/ILogger';
|
|
2
|
+
import Address = require('../Address');
|
|
3
|
+
/**
|
|
4
|
+
* Interface for node credentials
|
|
5
|
+
*/
|
|
6
|
+
export interface NodeCredentials {
|
|
7
|
+
uuid: string;
|
|
8
|
+
ownerUuid: string;
|
|
9
|
+
groupName: string;
|
|
10
|
+
groupPassword: string;
|
|
11
|
+
lastAuthenticated: number;
|
|
12
|
+
isOwner: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Service to preserve and restore authentication credentials across failover cycles
|
|
16
|
+
* This fixes the "Invalid Credentials" issue that occurs when nodes rejoin after failover
|
|
17
|
+
*/
|
|
18
|
+
export declare class CredentialPreservationService {
|
|
19
|
+
private readonly logger;
|
|
20
|
+
/**
|
|
21
|
+
* Stores authentication context for each node
|
|
22
|
+
*/
|
|
23
|
+
private nodeCredentials;
|
|
24
|
+
constructor(logger: ILogger);
|
|
25
|
+
/**
|
|
26
|
+
* Preserves authentication credentials for a node before it gets disconnected
|
|
27
|
+
* @param address The node address
|
|
28
|
+
* @param uuid The node's UUID
|
|
29
|
+
* @param ownerUuid The owner UUID
|
|
30
|
+
* @param groupName The group name
|
|
31
|
+
* @param groupPassword The group password
|
|
32
|
+
* @param isOwner Whether this is an owner connection
|
|
33
|
+
*/
|
|
34
|
+
preserveCredentials(address: Address, uuid: string, ownerUuid: string, groupName: string, groupPassword: string, isOwner: boolean): void;
|
|
35
|
+
/**
|
|
36
|
+
* Restores authentication credentials for a specific node
|
|
37
|
+
* @param address The node address
|
|
38
|
+
* @returns The preserved credentials or null if not found
|
|
39
|
+
*/
|
|
40
|
+
restoreCredentials(address: Address): NodeCredentials | null;
|
|
41
|
+
/**
|
|
42
|
+
* Updates credentials after successful authentication
|
|
43
|
+
* @param address The node address
|
|
44
|
+
* @param uuid The new UUID
|
|
45
|
+
* @param ownerUuid The new owner UUID
|
|
46
|
+
*/
|
|
47
|
+
updateCredentials(address: Address, uuid: string, ownerUuid: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Clears credentials for a specific node
|
|
50
|
+
* @param address The node address
|
|
51
|
+
*/
|
|
52
|
+
clearCredentials(address: Address): void;
|
|
53
|
+
/**
|
|
54
|
+
* Clears all stored credentials - used for cluster reset scenarios
|
|
55
|
+
*/
|
|
56
|
+
clearAllCredentials(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Cleans up stale credentials older than the specified age
|
|
59
|
+
* @param maxAgeMs Maximum age in milliseconds (default: 5 minutes)
|
|
60
|
+
*/
|
|
61
|
+
cleanupStaleCredentials(maxAgeMs?: number): void;
|
|
62
|
+
/**
|
|
63
|
+
* Gets a summary of preserved credentials for debugging
|
|
64
|
+
* @returns A summary string
|
|
65
|
+
*/
|
|
66
|
+
getCredentialsSummary(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Smart credential restoration that handles both scenarios:
|
|
69
|
+
* 1. If member added event occurred -> use new UUID
|
|
70
|
+
* 2. If no member added event -> use old UUID (node probably never changed)
|
|
71
|
+
* @param address The address to restore credentials for
|
|
72
|
+
* @param hasMemberAddedEvent Whether we received a member added event for this address
|
|
73
|
+
* @returns The appropriate credentials to use
|
|
74
|
+
*/
|
|
75
|
+
smartRestoreCredentials(address: Address, hasMemberAddedEvent?: boolean): NodeCredentials | null;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if we have valid credentials for an address
|
|
78
|
+
* @param address The address to check
|
|
79
|
+
* @returns True if we have valid credentials
|
|
80
|
+
*/
|
|
81
|
+
hasValidCredentials(address: Address): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Gets the last known UUID for an address
|
|
84
|
+
* @param address The address to get UUID for
|
|
85
|
+
* @returns The UUID or null if not found
|
|
86
|
+
*/
|
|
87
|
+
getLastKnownUuid(address: Address): string | null;
|
|
88
|
+
/**
|
|
89
|
+
* Updates the owner UUID for ALL preserved credentials
|
|
90
|
+
* This is called when cluster membership changes and we need to sync all credentials
|
|
91
|
+
* @param newOwnerUuid The new owner UUID from the current cluster state
|
|
92
|
+
*/
|
|
93
|
+
updateAllOwnerUuids(newOwnerUuid: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Gets the current owner UUID from preserved credentials
|
|
96
|
+
* @returns The current owner UUID or null if not found
|
|
97
|
+
*/
|
|
98
|
+
getCurrentOwnerUuid(): string | null;
|
|
99
|
+
/**
|
|
100
|
+
* Validates that all credentials have consistent owner UUIDs
|
|
101
|
+
* @returns True if all credentials are consistent, false otherwise
|
|
102
|
+
*/
|
|
103
|
+
validateOwnerUuidConsistency(): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Invalidates ALL credentials that have a specific owner UUID
|
|
106
|
+
* This is called when cluster membership changes and old owner UUIDs become invalid
|
|
107
|
+
* @param oldOwnerUuid The old owner UUID that is no longer valid
|
|
108
|
+
*/
|
|
109
|
+
invalidateCredentialsWithOwnerUuid(oldOwnerUuid: string): void;
|
|
110
|
+
/**
|
|
111
|
+
* Invalidates ALL credentials that don't match the current cluster owner UUID
|
|
112
|
+
* This ensures complete credential consistency across the entire cluster
|
|
113
|
+
* @param currentClusterOwnerUuid The current cluster owner UUID that should be valid
|
|
114
|
+
*/
|
|
115
|
+
invalidateAllCredentialsExceptCurrentOwner(currentClusterOwnerUuid: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Invalidates only problematic credentials while preserving working ones
|
|
118
|
+
* This prevents breaking working connections (like 192.168.1.108)
|
|
119
|
+
* @param currentClusterOwnerUuid The current cluster owner UUID that should be valid
|
|
120
|
+
*/
|
|
121
|
+
invalidateOnlyProblematicCredentials(currentClusterOwnerUuid: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* Checks if an address has had recent authentication issues
|
|
124
|
+
* This helps determine which credentials to invalidate
|
|
125
|
+
* @param addressStr The address to check
|
|
126
|
+
* @returns True if the address has recent auth issues
|
|
127
|
+
*/
|
|
128
|
+
private hasRecentAuthenticationIssues(addressStr);
|
|
129
|
+
/**
|
|
130
|
+
* Clears all credentials for a specific address
|
|
131
|
+
* This is called when we need to force fresh authentication for a node
|
|
132
|
+
* @param address The address to clear credentials for
|
|
133
|
+
*/
|
|
134
|
+
clearCredentialsForAddress(address: Address): void;
|
|
135
|
+
/**
|
|
136
|
+
* Gets all addresses that have credentials with a specific owner UUID
|
|
137
|
+
* @param ownerUuid The owner UUID to search for
|
|
138
|
+
* @returns Array of addresses that have credentials with this owner UUID
|
|
139
|
+
*/
|
|
140
|
+
getAddressesWithOwnerUuid(ownerUuid: string): string[];
|
|
141
|
+
}
|