Open kaihendry opened 5 years ago
The lambda generated from the SQL will look like this:
CALL mysql.lambda_asyncarn:aws:lambda:ap-southeast-1:192458993663:function:alambda_simple{"actionType": "CREATE_UNIT", "creatorId": "NXnKGEdEwEvMgWQtG", "name": "SG_SIN_LUM_36-01_05R", "moreInfo": null, "streetAddress": "Lumiere \n #36-01", "city": null, "state": "", "zipCode": null, "country": null, "ownerId": "NXnKGEdEwEvMgWQtG"}
@kaihendry this is most likely missing the id for the record from the origin.
Suggestion: name this unitCreationRequestId
I believe I need to POST to **POST Create a new unit by MEFE internal API*** with MEFE internal API.
An example payload is:
{
"actionType": "CREATE_UNIT",
"creatorId": "R4vBD6BZRCNx8JwnM",
"name": "Unit test 128288",
"type": "Villa",
"moreInfo": "lasdl",
"streetAddress": "asdads",
"city": "asdasd",
"state": "",
"zipCode": "292929",
"country": "Singapore"
}
So I will check for actionType for posting to /api/process-api-payload othewise it will post by default to /api/db-change-message/process
An example request and response from MEFE API to a request with an "actionType" of "CREATE_UNIT":
{
"actionType": "CREATE_UNIT",
"creatorId": "R4vBD6BZRCNx8JwnM",
"name": "Unit test 128288",
"type": "Villa",
"moreInfo": "lasdl",
"streetAddress": "asdads",
"city": "asdasd",
"state": "",
"zipCode": "292929",
"country": "Singapore"
}
{
"unitMongoId": "m3KTgSW2m1FSLSCnp",
"timestamp": "2019-03-18T03:37:03.179Z"
}
The SQL that will need to be run to update the SQL after the Unit is created (i.e: the MEFE API Returns a success):
SET @unit_creation_request_id = 'unitCreationRequestId';
SET @mefe_unit_id = 'unitMongoId (from_API_response)';
SET @creation_datetime = 'timestamp (from_API_response)';
CALL ut_creation_success_mefe_unit_id
;
Time stamp is just a string right? No special sql Type?
No environment variables, right?
Time stamp is just a string right? No special sql Type?
Timestamp is SQL datetime
No environment variables, right?
Not in v1.0
@franck-boullier I'm getting Error 1305: PROCEDURE bugzilla.ut_creation_success_mefe_unit_id does not exist
in the dev environment.
timestamp is an iso string date format (in the API response)
In order to capture the information 'was this unit there in Unee-T before or not?' we need to change the SQL as such:
SET @unit_creation_request_id = 'unitCreationRequestId';
SET @mefe_unit_id = 'unitMongoId (from_API_response)';
SET @creation_datetime = 'timestamp (from_API_response)';
SET @is_created_by_me = 0;
CALL ut_creation_success_mefe_unit_id
;
SET @unit_creation_request_id = 'unitCreationRequestId';
SET @mefe_unit_id = 'unitMongoId (from_API_response)';
SET @creation_datetime = 'timestamp (from_API_response)';
SET @is_created_by_me = 1;
CALL ut_creation_success_mefe_unit_id
;
Still the "Error 1305: PROCEDURE bugzilla.ut_creation_success_mefe_unit_id does not exist"
issue.
This is pending some lambda permissions setup (case id #5900089011) on UNEE-T_ENTERPRISE_RDS IIUC. @franck-boullier can you confirm I need to talk to this separate RDS instead instead of another database in auroradb.dev.unee-t.com?
@franck-boullier could you please test? Perhaps a different payload to my https://github.com/unee-t/lambda2sns/blob/master/tests/events/create_unit.json
AFAICT this works. If it doesn't please re-open and tell me how you tested it.
@kaihendry This does not seem to work as intended ---> re-opening this:
In the DEV/Staging environment: Create a new unit in the Unee-T Enterprise database
Lambda is fired out of the Unee-T Enterprise Database DEV/Staging. I can see that from the AWS notification message.
The payload is
{"city": null, "name": "test_unit_1", "state": null, "country": null, "ownerId": "YYeAutqzDY3MeqbNC", "zipCode": null, "moreInfo": "Test Unit 1 - created whith MEFE API.", "creatorId": "YYeAutqzDY3MeqbNC", "actionType": "CREATE_UNIT", "streetAddress": null, "unitCreationRequestId": 1}
Unit is NOT created in the Mongo DB
Unit is NOT created in the BZDb
Record for the created Unit is NOT updated in the Unee-T Enterprise database
@kaihendry any idea what might be happening?
You need to examine to logs or subscribe to the SNS. The failure seems to be payload failing with MEFE https://media.dev.unee-t.com/2019-03-24/log.png
IIUC null values are choking the MEFE API with "Match error: Expected string, got null"
Currently I do not parse the JSON message, I just relay it. For me to filter the JSON from null values, e.g.: https://play.golang.org/p/KuCfLW-o0GV
I would need to pedantically define the structure. If the structure changes, it will be a problem, since Golang is strongly typed. If the structure won't change, then fine, happy to implement it.
It's just that I think Javascript is better position to filter null values, since it's easier to do here and it wouldn't mean complexity is spread across two stacks (lambda & MEFE).
WDYT @nbiton ?
unitType was missing from the payload. NULL values error message was a red herring. Hopfully @nbiton will improve the error messages returned by the MEFE API. Thanks!
@nbiton in the payload the ownerId
seems to be missing.
Is the creatorId
the same as the MEFE concept ownerId
?
I'd prefer to have something like
{
"actionType": "CREATE_UNIT",
"creatorId": "R4vBD6BZRCNx8JwnM",
"name": "Unit test 128288",
"type": "Villa",
"moreInfo": "lasdl",
"streetAddress": "asdads",
"city": "asdasd",
"state": "",
"zipCode": "292929",
"country": "Singapore",
"ownerId": "R4vBD6BZRCNx8JwnM"
}
"ownerId" can also be provided. It is an optional param. The "creatorId" is uswd as default
I got in the logs
Error: 400 Bad Request from MEFE: https://case.dev.unee-t.com/api/process-api-payload?accessToken=xxxxxxxx, Response: "Match error: Expected string, got null" from Request: {"city": null, "name": "TEST_B_1", "type": "Condominium", "state": null, "country": null, "ownerId": "YYeAutqzDY3MeqbNC", "zipCode": null, "moreInfo": "Test Building 1", "creatorId": "YYeAutqzDY3MeqbNC", "actionType": "CREATE_UNIT", "streetAddress": null, "unitCreationRequestId": 1}
You can also subscribe to the arn:aws:sns:ap-southeast-1:812644853088:process-api-payload to receive these errors to your inbox.
Still unable to create a unit. I know it went through (lambda was fired correctly) but nothing happened on the MEFE side.
The payload:
''' {"city": null, "name": "TEST_B_1", "type": "Condominium", "state": null, "country": null, "ownerId": "YYeAutqzDY3MeqbNC", "zipCode": null, "moreInfo": "Test Building 1", "creatorId": "YYeAutqzDY3MeqbNC", "actionType": "CREATE_UNIT", "streetAddress": null, "unitCreationRequestId": 1} '''
@kaihendry and @nbiton any idea on how we can fix this?
I got in the logs
What's the fix then?
You can also subscribe to the arn:aws:sns:ap-southeast-1:812644853088:process-api-payload to receive these errors to your inbox.
There's no real point really: it'll be massively inefficient for me to try to debug this TBH...
Isn't unitType missing from your payload again? https://github.com/unee-t/lambda2sns/issues/9#issuecomment-476035471
Isn't unitType missing from your payload again? #9 (comment)
@kaihendry I have specified the Unit Type as described by @nbiton here: https://github.com/unee-t/lambda2sns/issues/9#issuecomment-474168618
i.e I used type
(as specified) and not unitType
What is the correct syntax? type
or unitType
?
I updated the request in Postman "Create a new unit by MEFE internal API*" to include the "ownerId" param. "type" was already there.
I updated my code to use unitType
instead of type
Still no luck ---> unit does not seem to have been created...
The payload:
{"city": null, "name": "TEST_B_2", "state": null, "country": null, "ownerId": "YYeAutqzDY3MeqbNC", "zipCode": null, "moreInfo": "Test 2 Building created with API.", "unitType": "Condominium", "creatorId": "YYeAutqzDY3MeqbNC", "actionType": "CREATE_UNIT", "streetAddress": null, "unitCreationRequestId": 2}
I updated my code again to use type
instead of unitType
Still no luck ---> unit does not seem to have been created...
The payload:
{"city": null, "name": "TEST_B_3", "type": "Condominium", "state": null, "country": null, "ownerId": "YYeAutqzDY3MeqbNC", "zipCode": null, "moreInfo": "Test 3 - Building - created with MEFE API.", "creatorId": "YYeAutqzDY3MeqbNC", "actionType": "CREATE_UNIT", "streetAddress": null, "unitCreationRequestId": 3}
Replacing NULL
values with '' (empty)
The payload is now
{"city": "", "name": "TEST_B_4", "type": "Condominium", "state": "", "country": "", "ownerId": "YYeAutqzDY3MeqbNC", "zipCode": "", "moreInfo": "Test 4 - replace NULL with '' if needed - MEFE API to create unit.", "creatorId": "YYeAutqzDY3MeqbNC", "actionType": "CREATE_UNIT", "streetAddress": "", "unitCreationRequestId": 4}
This seem to have been working as intended. Thanks for the help @kaihendry!
@kaihendry This does not seem to work as intended ---> re-opening this:
In the Demo environment: Create 3 new units in the Unee-T Enterprise database
ut_map_external_source_units
with the MEFE unit id and the timestamp when these units were created.ut_map_external_source_units
(expected 3 records updated).{"city": "Singapore ", "name": "Loft @ Holland - 1", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": null, "zipCode": "278580", "moreInfo": "Loft@Holland is a freehold condominium development located at 151 Holland Road, Singapore 278580, in district 10. Expected to be completed in 2015, it stands 5 storeys tall and comprises a total of 41 units. Loft@Holland is relatively close to Holland Village MRT Station.\r\n\r\nCondo Facilities at Loft@Holland\r\n\r\nFacilities at Loft@Holland include swimming pool, pool deck and gym.\r\n\r\nCondo Amenities near Loft@Holland\r\n\r\nThe schools in the vicinity are New Town Primary School, Dunman High School and Clementi Town Secondary School.\r\n\r\nFor daily necessities and shopping needs, residents can head down to several shopping centres located within walking distance, such as Holland Village Shopping Mall.\r\n\r\nFor vehicle owners, driving from Loft@Holland to Orchard Road or Central Business District (CBD) takes about 5-10 minutes, via the Central Expressway (CTE). ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": "151 Holland Road \n", "unitCreationRequestId": 1046}
{"city": "Singapore", "name": "Seahill - 119", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": null, "zipCode": "126777", "moreInfo": "Seahill is a 99-Year Leasehold Condominium located at 119, West Coast Crescent, 126777 in District 05. It comprises of 338 Units. Seahill is close to Clementi MRT (EW23). It is completed in 2016. Schools close to Seahill include Farrer Park Primary School, Saint Joseph’s Institution Junior and Stamford Primary School.\r\n\r\nFacilities in Seahill\r\n\r\nFacilities at Seahill include Sky Pool, Water Feature with Sunken Planter, 50M Lap Pool, Spa Island, Kids Pool, Dining Pavilion, Spa Pool, Massage Pavilion and Lounge Deck, Aqua Gym, Sea Mist Spa Pool, Function Deck, Meeting Pavilion, Jogging Track, Outdoor Fitness, Children Playground, Viewing Pavilion, Fitness Balcony and Plunge Pool.\r\n\r\nAmenities near Seahill\r\n\r\nResidents at Seahill can get to nearby supermarkets or shopping mall within the area for an array of amenities such as grocery and retail shopping, bank, eateries and more.\r\n\r\nSeahill is near to NTUC Fairprice, Cold Storage and Sheng Siong Supermarket. It is also close to West Coast Plaza.\r\n\r\nVehicle owners can take West Coast Highway, Clementi Road and Ayer Rajah Expressway (AYE) to get to the business hub or shopping district in the city. ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": "119 West Coast Crescent \n", "unitCreationRequestId": 1047}
{"city": "Singapore", "name": "The Estuary - 1", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": null, "zipCode": null, "moreInfo": "The Estuary\r\n\r\nA 99-year leasehold development located at 85 Yishun Avenue 1 Singapore 769132, in district 27\r\n\r\n* Completed in 2013, comprise of 608 units\r\n* Located near Khatib MRT Station\r\n* Located close to North point shopping centreand Yishun sports centre\r\n\r\nFacilitiles at The Estuary\r\n\r\n* Facilities include BBQ pit, clubhouse, fitness corner, gym, lap pool, fun pool, multi-purpose hall, steambath, playground and tennis court\r\n\r\nAmenities near The Estuary\r\n\r\n* Yishun Junior College and Chung Cheng High school", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": " \n", "unitCreationRequestId": 1050}
@kaihendry any idea what might be happening?
@nbiton how is it even possible that the units are created in the BZ Database and NOT created in the Mongo database??
I just spotted that the ownerId
was null
in the payload ---> this might be why things are broken.
I'll fix this
BUT we still need to plug that issue anyway: if an ownerId
is set to null
it seems that the MEFE API still partially creates Unee-T unit in a apparently very random manner:
In the Demo environment: Create 3 new units in the Unee-T Enterprise database
ut_map_external_source_units
with the MEFE unit id and the timestamp when these units were created.ut_map_external_source_units
(expected 3 records updated).{"city": "Singapore ", "name": "Loft @ Holland - 1", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": "278580", "moreInfo": "Loft@Holland is a freehold condominium development located at 151 Holland Road, Singapore 278580, in district 10. Expected to be completed in 2015, it stands 5 storeys tall and comprises a total of 41 units. Loft@Holland is relatively close to Holland Village MRT Station.\r\n\r\nCondo Facilities at Loft@Holland\r\n\r\nFacilities at Loft@Holland include swimming pool, pool deck and gym.\r\n\r\nCondo Amenities near Loft@Holland\r\n\r\nThe schools in the vicinity are New Town Primary School, Dunman High School and Clementi Town Secondary School.\r\n\r\nFor daily necessities and shopping needs, residents can head down to several shopping centres located within walking distance, such as Holland Village Shopping Mall.\r\n\r\nFor vehicle owners, driving from Loft@Holland to Orchard Road or Central Business District (CBD) takes about 5-10 minutes, via the Central Expressway (CTE). ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": "151 Holland Road \n", "unitCreationRequestId": 1046}
{"city": "Singapore", "name": "Seahill - 119", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": "126777", "moreInfo": "Seahill is a 99-Year Leasehold Condominium located at 119, West Coast Crescent, 126777 in District 05. It comprises of 338 Units. Seahill is close to Clementi MRT (EW23). It is completed in 2016. Schools close to Seahill include Farrer Park Primary School, Saint Joseph’s Institution Junior and Stamford Primary School.\r\n\r\nFacilities in Seahill\r\n\r\nFacilities at Seahill include Sky Pool, Water Feature with Sunken Planter, 50M Lap Pool, Spa Island, Kids Pool, Dining Pavilion, Spa Pool, Massage Pavilion and Lounge Deck, Aqua Gym, Sea Mist Spa Pool, Function Deck, Meeting Pavilion, Jogging Track, Outdoor Fitness, Children Playground, Viewing Pavilion, Fitness Balcony and Plunge Pool.\r\n\r\nAmenities near Seahill\r\n\r\nResidents at Seahill can get to nearby supermarkets or shopping mall within the area for an array of amenities such as grocery and retail shopping, bank, eateries and more.\r\n\r\nSeahill is near to NTUC Fairprice, Cold Storage and Sheng Siong Supermarket. It is also close to West Coast Plaza.\r\n\r\nVehicle owners can take West Coast Highway, Clementi Road and Ayer Rajah Expressway (AYE) to get to the business hub or shopping district in the city. ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": "119 West Coast Crescent \n", "unitCreationRequestId": 1047}
{"city": "Singapore", "name": "The Estuary - 1", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": null, "moreInfo": "The Estuary\r\n\r\nA 99-year leasehold development located at 85 Yishun Avenue 1 Singapore 769132, in district 27\r\n\r\n* Completed in 2013, comprise of 608 units\r\n* Located near Khatib MRT Station\r\n* Located close to North point shopping centreand Yishun sports centre\r\n\r\nFacilitiles at The Estuary\r\n\r\n* Facilities include BBQ pit, clubhouse, fitness corner, gym, lap pool, fun pool, multi-purpose hall, steambath, playground and tennis court\r\n\r\nAmenities near The Estuary\r\n\r\n* Yishun Junior College and Chung Cheng High school", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": " \n", "unitCreationRequestId": 1050}
ownerId
in the payload.Pulled out the logs from the demo env and interestingly it mentions "Error: failed [400] Error 1213: Deadlock found when trying to get lock; try restarting transaction [Unit creation API Lambda error]
In the Demo environment:
Logged as the SQL user lambda_invoker
(previous tests were done logged in the SQL as root
)
Create 3 new units in the Unee-T Enterprise database
ut_map_external_source_units
with the MEFE unit id and the timestamp when these units were created.ut_map_external_source_units
(expected 3 records updated).{"city": "Singapore ", "name": "Loft @ Holland - 1", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": "278580", "moreInfo": "Loft@Holland is a freehold condominium development located at 151 Holland Road, Singapore 278580, in district 10. Expected to be completed in 2015, it stands 5 storeys tall and comprises a total of 41 units. Loft@Holland is relatively close to Holland Village MRT Station.\r\n\r\nCondo Facilities at Loft@Holland\r\n\r\nFacilities at Loft@Holland include swimming pool, pool deck and gym.\r\n\r\nCondo Amenities near Loft@Holland\r\n\r\nThe schools in the vicinity are New Town Primary School, Dunman High School and Clementi Town Secondary School.\r\n\r\nFor daily necessities and shopping needs, residents can head down to several shopping centres located within walking distance, such as Holland Village Shopping Mall.\r\n\r\nFor vehicle owners, driving from Loft@Holland to Orchard Road or Central Business District (CBD) takes about 5-10 minutes, via the Central Expressway (CTE). ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": "151 Holland Road \n", "unitCreationRequestId": 1046}
{"city": "Singapore", "name": "Seahill - 119", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": "126777", "moreInfo": "Seahill is a 99-Year Leasehold Condominium located at 119, West Coast Crescent, 126777 in District 05. It comprises of 338 Units. Seahill is close to Clementi MRT (EW23). It is completed in 2016. Schools close to Seahill include Farrer Park Primary School, Saint Joseph’s Institution Junior and Stamford Primary School.\r\n\r\nFacilities in Seahill\r\n\r\nFacilities at Seahill include Sky Pool, Water Feature with Sunken Planter, 50M Lap Pool, Spa Island, Kids Pool, Dining Pavilion, Spa Pool, Massage Pavilion and Lounge Deck, Aqua Gym, Sea Mist Spa Pool, Function Deck, Meeting Pavilion, Jogging Track, Outdoor Fitness, Children Playground, Viewing Pavilion, Fitness Balcony and Plunge Pool.\r\n\r\nAmenities near Seahill\r\n\r\nResidents at Seahill can get to nearby supermarkets or shopping mall within the area for an array of amenities such as grocery and retail shopping, bank, eateries and more.\r\n\r\nSeahill is near to NTUC Fairprice, Cold Storage and Sheng Siong Supermarket. It is also close to West Coast Plaza.\r\n\r\nVehicle owners can take West Coast Highway, Clementi Road and Ayer Rajah Expressway (AYE) to get to the business hub or shopping district in the city. ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": "119 West Coast Crescent \n", "unitCreationRequestId": 1047}
{"city": "Singapore", "name": "The Estuary - 1", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": null, "moreInfo": "The Estuary\r\n\r\nA 99-year leasehold development located at 85 Yishun Avenue 1 Singapore 769132, in district 27\r\n\r\n* Completed in 2013, comprise of 608 units\r\n* Located near Khatib MRT Station\r\n* Located close to North point shopping centreand Yishun sports centre\r\n\r\nFacilitiles at The Estuary\r\n\r\n* Facilities include BBQ pit, clubhouse, fitness corner, gym, lap pool, fun pool, multi-purpose hall, steambath, playground and tennis court\r\n\r\nAmenities near The Estuary\r\n\r\n* Yishun Junior College and Chung Cheng High school", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": " \n", "unitCreationRequestId": 1050}
To summarize:
Error 1062: Duplicate entry '32767' for key 'PRIMARY'
How (could) we fix this?
I opened the following issue
In the Demo environment:
Logged as the SQL user root
Create 3 new units in the Unee-T Enterprise database
ut_map_external_source_units
with the MEFE unit id and the timestamp when these units were created.ut_map_external_source_units
(expected 3 records updated).
{"city": "Singapore ", "name": "Loft @ Holland - 1", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": "278580", "moreInfo": "Loft@Holland is a freehold condominium development located at 151 Holland Road, Singapore 278580, in district 10. Expected to be completed in 2015, it stands 5 storeys tall and comprises a total of 41 units. Loft@Holland is relatively close to Holland Village MRT Station.\r\n\r\nCondo Facilities at Loft@Holland\r\n\r\nFacilities at Loft@Holland include swimming pool, pool deck and gym.\r\n\r\nCondo Amenities near Loft@Holland\r\n\r\nThe schools in the vicinity are New Town Primary School, Dunman High School and Clementi Town Secondary School.\r\n\r\nFor daily necessities and shopping needs, residents can head down to several shopping centres located within walking distance, such as Holland Village Shopping Mall.\r\n\r\nFor vehicle owners, driving from Loft@Holland to Orchard Road or Central Business District (CBD) takes about 5-10 minutes, via the Central Expressway (CTE). ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": "151 Holland Road \n", "unitCreationRequestId": 1046}
{"city": "Singapore", "name": "Seahill - 119", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": "126777", "moreInfo": "Seahill is a 99-Year Leasehold Condominium located at 119, West Coast Crescent, 126777 in District 05. It comprises of 338 Units. Seahill is close to Clementi MRT (EW23). It is completed in 2016. Schools close to Seahill include Farrer Park Primary School, Saint Joseph’s Institution Junior and Stamford Primary School.\r\n\r\nFacilities in Seahill\r\n\r\nFacilities at Seahill include Sky Pool, Water Feature with Sunken Planter, 50M Lap Pool, Spa Island, Kids Pool, Dining Pavilion, Spa Pool, Massage Pavilion and Lounge Deck, Aqua Gym, Sea Mist Spa Pool, Function Deck, Meeting Pavilion, Jogging Track, Outdoor Fitness, Children Playground, Viewing Pavilion, Fitness Balcony and Plunge Pool.\r\n\r\nAmenities near Seahill\r\n\r\nResidents at Seahill can get to nearby supermarkets or shopping mall within the area for an array of amenities such as grocery and retail shopping, bank, eateries and more.\r\n\r\nSeahill is near to NTUC Fairprice, Cold Storage and Sheng Siong Supermarket. It is also close to West Coast Plaza.\r\n\r\nVehicle owners can take West Coast Highway, Clementi Road and Ayer Rajah Expressway (AYE) to get to the business hub or shopping district in the city. ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": "119 West Coast Crescent \n", "unitCreationRequestId": 1047}
{"city": "Singapore", "name": "The Estuary - 1", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": null, "moreInfo": "The Estuary\r\n\r\nA 99-year leasehold development located at 85 Yishun Avenue 1 Singapore 769132, in district 27\r\n\r\n* Completed in 2013, comprise of 608 units\r\n* Located near Khatib MRT Station\r\n* Located close to North point shopping centreand Yishun sports centre\r\n\r\nFacilitiles at The Estuary\r\n\r\n* Facilities include BBQ pit, clubhouse, fitness corner, gym, lap pool, fun pool, multi-purpose hall, steambath, playground and tennis court\r\n\r\nAmenities near The Estuary\r\n\r\n* Yishun Junior College and Chung Cheng High school", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": " \n", "unitCreationRequestId": 1050}
Update from @kaihendry in another issue ---> copied there as it belongs here:
We seem to have a failure
Error 1213: Deadlock found when trying to get lock; try restarting transaction
This happens when the lambda is trying to call the procedure https://github.com/unee-t/unit
The most logical explanation for this is that the process who is trying to trigger the BZ procedure to create a unit is not patient enough ---> it does not give the previous run enough time to release the lock before it tries to create another unit ---> we see the error message
Error 1213: Deadlock found when trying to get lock; try restarting transaction
I adjusted the timeout on https://github.com/unee-t/unit in the demo env to 30s. But I didn't see any evidence of a timeout in the logs.
After timeout extended by @kaihendry
In the Demo environment:
Logged as the SQL user root
Create 3 new units in the Unee-T Enterprise database
ut_map_external_source_units
with the MEFE unit id and the timestamp when these units were created.ut_map_external_source_units
(expected 3 records updated).
{"city": "Singapore ", "name": "Loft @ Holland - 1", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": "278580", "moreInfo": "Loft@Holland is a freehold condominium development located at 151 Holland Road, Singapore 278580, in district 10. Expected to be completed in 2015, it stands 5 storeys tall and comprises a total of 41 units. Loft@Holland is relatively close to Holland Village MRT Station.\r\n\r\nCondo Facilities at Loft@Holland\r\n\r\nFacilities at Loft@Holland include swimming pool, pool deck and gym.\r\n\r\nCondo Amenities near Loft@Holland\r\n\r\nThe schools in the vicinity are New Town Primary School, Dunman High School and Clementi Town Secondary School.\r\n\r\nFor daily necessities and shopping needs, residents can head down to several shopping centres located within walking distance, such as Holland Village Shopping Mall.\r\n\r\nFor vehicle owners, driving from Loft@Holland to Orchard Road or Central Business District (CBD) takes about 5-10 minutes, via the Central Expressway (CTE). ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": "151 Holland Road \n", "unitCreationRequestId": 1046}
{"city": "Singapore", "name": "Seahill - 119", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": "126777", "moreInfo": "Seahill is a 99-Year Leasehold Condominium located at 119, West Coast Crescent, 126777 in District 05. It comprises of 338 Units. Seahill is close to Clementi MRT (EW23). It is completed in 2016. Schools close to Seahill include Farrer Park Primary School, Saint Joseph’s Institution Junior and Stamford Primary School.\r\n\r\nFacilities in Seahill\r\n\r\nFacilities at Seahill include Sky Pool, Water Feature with Sunken Planter, 50M Lap Pool, Spa Island, Kids Pool, Dining Pavilion, Spa Pool, Massage Pavilion and Lounge Deck, Aqua Gym, Sea Mist Spa Pool, Function Deck, Meeting Pavilion, Jogging Track, Outdoor Fitness, Children Playground, Viewing Pavilion, Fitness Balcony and Plunge Pool.\r\n\r\nAmenities near Seahill\r\n\r\nResidents at Seahill can get to nearby supermarkets or shopping mall within the area for an array of amenities such as grocery and retail shopping, bank, eateries and more.\r\n\r\nSeahill is near to NTUC Fairprice, Cold Storage and Sheng Siong Supermarket. It is also close to West Coast Plaza.\r\n\r\nVehicle owners can take West Coast Highway, Clementi Road and Ayer Rajah Expressway (AYE) to get to the business hub or shopping district in the city. ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": "119 West Coast Crescent \n", "unitCreationRequestId": 1047}
{"city": "Singapore", "name": "The Estuary - 1", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "hF4AxDx6r6ue2TgFD", "zipCode": null, "moreInfo": "The Estuary\r\n\r\nA 99-year leasehold development located at 85 Yishun Avenue 1 Singapore 769132, in district 27\r\n\r\n* Completed in 2013, comprise of 608 units\r\n* Located near Khatib MRT Station\r\n* Located close to North point shopping centreand Yishun sports centre\r\n\r\nFacilitiles at The Estuary\r\n\r\n* Facilities include BBQ pit, clubhouse, fitness corner, gym, lap pool, fun pool, multi-purpose hall, steambath, playground and tennis court\r\n\r\nAmenities near The Estuary\r\n\r\n* Yishun Junior College and Chung Cheng High school", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "CREATE_UNIT", "streetAddress": " \n", "unitCreationRequestId": 1050}
Looking at the BZ side we can see that Unit 3 exists in the table ut_data_to_create_units
Manually running the BZ script to create the unit in BZ (the script is available here: https://github.com/unee-t/unit/blob/master/sql/unit_create_new.sql
# The unit: What is the id of the unit in the table 'ut_data_to_create_units'
SET @mefe_unit_id = 'o8eywFtpiUG3nDrgR';
#
# Environment: Which environment are you creating the unit in?
# - 1 is for the DEV/Staging
# - 2 is for the prod environment
# - 3 is for the Demo environment
SET @environment = 3;
#
########################################################################
#
# ALL THE VARIABLES WE NEED HAVE BEEN DEFINED, WE CAN RUN THE SCRIPT
#
########################################################################
# We have everything, we need. We can call the script now
CALL `unit_create_with_dummy_users`;
We still don't understand why is the Unee-T sub-component https://github.com/unee-t/unit is not able to run the script... @kaihendry I'll need your insights on that as all seems OK on the SQL side AFAICT.
IIUC this is due to a deadlock issue in the procedure diagnosed with SHOW ENGINE INNODB STATUS \G
& not problem per se in https://github.com/unee-t/lambda2sns or https://github.com/unee-t/unit.
Based on findings from @kaihendry
The object holding the lock is the procedure update_log_count_enabled_units
This is a procedure that is called by the trigger update_the_log_of_enabled_units_when_unit_is_created
which is activated each time a new unit is added to the products
table
Disable the trigger update_the_log_of_enabled_units_when_unit_is_created
In the Demo environment:
Logged as the SQL user root
Create 6 new units in the Unee-T Enterprise database
Check if we still have the deadlock issue
ut_map_external_source_units
with the MEFE unit id and the timestamp when these units were created. - PASSEDRemoving the trigger update_the_log_of_enabled_units_when_unit_is_created
in the BZ database fixed the deadlock issue.
This is a workaround that we will use for now until we can find a way to re-enable the trigger update_the_log_of_enabled_units_when_unit_is_created
without creating deadlocks.
This doesn't work in the DEV/Staging environment :triumph:
Create 6 units in the Unee-T Enterprise DB.
All 6 units are created in the MEFE - FAILED
{"city": "Singapore", "name": "Heritage View - A", "type": "Condominium", "state": null, "country": "Singapore", "ownerId": "YYeAutqzDY3MeqbNC", "zipCode": "138679", "moreInfo": null, "creatorId": "YYeAutqzDY3MeqbNC", "actionType": "CREATE_UNIT", "streetAddress": "8 Dover Rise \n", "unitCreationRequestId": 1048}
Problem is fixed.
Source of the issue was that the procedure unit_create_with_dummy_users
in the BZ database had been emptied for some reason :scream: ...
Creating a GH issue in the bz DB repo about that.
More tests done in the DEV/Staging uncovered new issues:
Create 497 units with the Une-T Enterprise database
---> 422 units were NOT properly created in Unee-T ---> 75 units are created in the BZ database (there seem to be no zombie units)
@kaihendry this looks like another timeout issue again :thinking:
We need to know the JSON payloads and the SQL queries itemised step by step.