Skip to content

Commit 442ff58

Browse files
authored
PHP-1741: Remove getServer from APM event classes (#1652)
* PHP-1741: Remove getServer from APM event classes This also removes the internal Manager reference. * Remove manager field from APM event structs * Remove disableClientPersistence tests for APM events
1 parent 96b387f commit 442ff58

22 files changed

+12
-545
lines changed

UPGRADE-2.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
UPGRADE FROM 1.x to 2.0
2+
=======================
3+
4+
* The `getServer()` method has been removed from the CommandFailedEvent,
5+
CommandStartedEvent, and CommandSucceededEvent event classes. The `getHost()`
6+
and `getPort()` methods have been added in its place.

src/MongoDB/Monitoring/CommandFailedEvent.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getRequestId)
138138
RETVAL_STRING(request_id);
139139
}
140140

141-
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer)
142-
{
143-
php_phongo_commandfailedevent_t* intern;
144-
145-
intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
146-
147-
PHONGO_PARSE_PARAMETERS_NONE();
148-
149-
phongo_server_init(return_value, &intern->manager, intern->server_id);
150-
}
151-
152141
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServiceId)
153142
{
154143
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
@@ -195,10 +184,6 @@ static void php_phongo_commandfailedevent_free_object(zend_object* object)
195184
zval_ptr_dtor(&intern->z_error);
196185
}
197186

198-
if (!Z_ISUNDEF(intern->manager)) {
199-
zval_ptr_dtor(&intern->manager);
200-
}
201-
202187
if (intern->reply) {
203188
bson_destroy(intern->reply);
204189
}
@@ -235,7 +220,7 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zend_object* obje
235220

236221
intern = Z_OBJ_COMMANDFAILEDEVENT(object);
237222
*is_temp = 1;
238-
array_init_size(&retval, 11);
223+
array_init_size(&retval, 10);
239224

240225
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
241226
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
@@ -258,13 +243,6 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zend_object* obje
258243
snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
259244
ADD_ASSOC_STRING(&retval, "requestId", request_id);
260245

261-
{
262-
zval server;
263-
264-
phongo_server_init(&server, &intern->manager, intern->server_id);
265-
ADD_ASSOC_ZVAL_EX(&retval, "server", &server);
266-
}
267-
268246
if (intern->has_service_id) {
269247
zval service_id;
270248

src/MongoDB/Monitoring/CommandFailedEvent.stub.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ final public function getReply(): object {}
3030

3131
final public function getRequestId(): string {}
3232

33-
/** @deprecated */
34-
final public function getServer(): \MongoDB\Driver\Server {}
35-
3633
final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}
3734

3835
final public function getServerConnectionId(): ?int {}

src/MongoDB/Monitoring/CommandFailedEvent_arginfo.h

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MongoDB/Monitoring/CommandStartedEvent.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId)
116116
RETVAL_STRING(request_id);
117117
}
118118

119-
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer)
120-
{
121-
php_phongo_commandstartedevent_t* intern;
122-
123-
intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
124-
125-
PHONGO_PARSE_PARAMETERS_NONE();
126-
127-
phongo_server_init(return_value, &intern->manager, intern->server_id);
128-
}
129-
130119
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServiceId)
131120
{
132121
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
@@ -169,10 +158,6 @@ static void php_phongo_commandstartedevent_free_object(zend_object* object)
169158

170159
zend_object_std_dtor(&intern->std);
171160

172-
if (!Z_ISUNDEF(intern->manager)) {
173-
zval_ptr_dtor(&intern->manager);
174-
}
175-
176161
if (intern->command) {
177162
bson_destroy(intern->command);
178163
}
@@ -209,7 +194,7 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zend_object* obj
209194

210195
intern = Z_OBJ_COMMANDSTARTEDEVENT(object);
211196
*is_temp = 1;
212-
array_init_size(&retval, 10);
197+
array_init_size(&retval, 9);
213198

214199
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
215200
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
@@ -229,13 +214,6 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zend_object* obj
229214
snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
230215
ADD_ASSOC_STRING(&retval, "requestId", request_id);
231216

232-
{
233-
zval server;
234-
235-
phongo_server_init(&server, &intern->manager, intern->server_id);
236-
ADD_ASSOC_ZVAL_EX(&retval, "server", &server);
237-
}
238-
239217
if (intern->has_service_id) {
240218
zval service_id;
241219

src/MongoDB/Monitoring/CommandStartedEvent.stub.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ final public function getPort(): int {}
2626

2727
final public function getRequestId(): string {}
2828

29-
/** @deprecated */
30-
final public function getServer(): \MongoDB\Driver\Server {}
31-
3229
final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}
3330

3431
final public function getServerConnectionId(): ?int {}

src/MongoDB/Monitoring/CommandStartedEvent_arginfo.h

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MongoDB/Monitoring/CommandSucceededEvent.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getRequestId)
127127
RETVAL_STRING(request_id);
128128
}
129129

130-
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServer)
131-
{
132-
php_phongo_commandsucceededevent_t* intern;
133-
134-
intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
135-
136-
PHONGO_PARSE_PARAMETERS_NONE();
137-
138-
phongo_server_init(return_value, &intern->manager, intern->server_id);
139-
}
140-
141130
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServiceId)
142131
{
143132
php_phongo_commandsucceededevent_t* intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
@@ -180,10 +169,6 @@ static void php_phongo_commandsucceededevent_free_object(zend_object* object)
180169

181170
zend_object_std_dtor(&intern->std);
182171

183-
if (!Z_ISUNDEF(intern->manager)) {
184-
zval_ptr_dtor(&intern->manager);
185-
}
186-
187172
if (intern->reply) {
188173
bson_destroy(intern->reply);
189174
}
@@ -220,7 +205,7 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zend_object* o
220205

221206
intern = Z_OBJ_COMMANDSUCCEEDEDEVENT(object);
222207
*is_temp = 1;
223-
array_init_size(&retval, 10);
208+
array_init_size(&retval, 9);
224209

225210
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
226211
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
@@ -240,13 +225,6 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zend_object* o
240225
snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
241226
ADD_ASSOC_STRING(&retval, "requestId", request_id);
242227

243-
{
244-
zval server;
245-
246-
phongo_server_init(&server, &intern->manager, intern->server_id);
247-
ADD_ASSOC_ZVAL_EX(&retval, "server", &server);
248-
}
249-
250228
if (intern->has_service_id) {
251229
zval service_id;
252230

src/MongoDB/Monitoring/CommandSucceededEvent.stub.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ final public function getReply(): object {}
2828

2929
final public function getRequestId(): string {}
3030

31-
/** @deprecated */
32-
final public function getServer(): \MongoDB\Driver\Server {}
33-
3431
final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}
3532

3633
final public function getServerConnectionId(): ?int {}

src/MongoDB/Monitoring/CommandSucceededEvent_arginfo.h

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/phongo_apm.c

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,6 @@ static HashTable* phongo_apm_get_subscribers_to_notify(zend_class_entry* subscri
7979
return subscribers;
8080
}
8181

82-
/* Search for a Manager associated with the given client in the request-scoped
83-
* registry. If any Manager is found, copy it to @out, increment its ref-count,
84-
* and return true; otherwise, set @out to undefined and return false. */
85-
static bool phongo_apm_copy_manager_for_client(mongoc_client_t* client, zval* out)
86-
{
87-
php_phongo_manager_t* manager;
88-
89-
ZVAL_UNDEF(out);
90-
91-
if (!MONGODB_G(managers) || zend_hash_num_elements(MONGODB_G(managers)) == 0) {
92-
return false;
93-
}
94-
95-
ZEND_HASH_FOREACH_PTR(MONGODB_G(managers), manager)
96-
{
97-
if (manager->client == client) {
98-
ZVAL_OBJ(out, &manager->std);
99-
Z_ADDREF_P(out);
100-
101-
return true;
102-
}
103-
}
104-
ZEND_HASH_FOREACH_END();
105-
106-
return false;
107-
}
108-
10982
/* Dispatch an event to all subscribers in a HashTable. The caller is
11083
* responsible for ensuring that subscribers implement the correct interface. */
11184
static void phongo_apm_dispatch_event(HashTable* subscribers, const char* function_name, zval* event)
@@ -158,13 +131,6 @@ static void phongo_apm_command_started(const mongoc_apm_command_started_t* event
158131
bson_oid_copy(mongoc_apm_command_started_get_service_id(event), &p_event->service_id);
159132
}
160133

161-
if (!phongo_apm_copy_manager_for_client(client, &p_event->manager)) {
162-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Found no Manager for client in APM event context");
163-
zval_ptr_dtor(&z_event);
164-
165-
goto cleanup;
166-
}
167-
168134
phongo_apm_dispatch_event(subscribers, "commandStarted", &z_event);
169135
zval_ptr_dtor(&z_event);
170136

@@ -207,13 +173,6 @@ static void phongo_apm_command_succeeded(const mongoc_apm_command_succeeded_t* e
207173
bson_oid_copy(mongoc_apm_command_succeeded_get_service_id(event), &p_event->service_id);
208174
}
209175

210-
if (!phongo_apm_copy_manager_for_client(client, &p_event->manager)) {
211-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Found no Manager for client in APM event context");
212-
zval_ptr_dtor(&z_event);
213-
214-
goto cleanup;
215-
}
216-
217176
phongo_apm_dispatch_event(subscribers, "commandSucceeded", &z_event);
218177
zval_ptr_dtor(&z_event);
219178

@@ -257,13 +216,6 @@ static void phongo_apm_command_failed(const mongoc_apm_command_failed_t* event)
257216
bson_oid_copy(mongoc_apm_command_failed_get_service_id(event), &p_event->service_id);
258217
}
259218

260-
if (!phongo_apm_copy_manager_for_client(client, &p_event->manager)) {
261-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Found no Manager for client in APM event context");
262-
zval_ptr_dtor(&z_event);
263-
264-
goto cleanup;
265-
}
266-
267219
/* We need to process and convert the error right here, otherwise
268220
* debug_info will turn into a recursive loop, and with the wrong trace
269221
* locations */

src/phongo_structs.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ typedef struct {
281281
} php_phongo_utcdatetime_t;
282282

283283
typedef struct {
284-
zval manager;
285284
char* command_name;
286285
char* database_name;
287286
uint32_t server_id;
@@ -298,7 +297,6 @@ typedef struct {
298297
} php_phongo_commandfailedevent_t;
299298

300299
typedef struct {
301-
zval manager;
302300
char* command_name;
303301
char* database_name;
304302
uint32_t server_id;
@@ -313,7 +311,6 @@ typedef struct {
313311
} php_phongo_commandstartedevent_t;
314312

315313
typedef struct {
316-
zval manager;
317314
char* command_name;
318315
char* database_name;
319316
uint32_t server_id;

0 commit comments

Comments
 (0)