Deadlock management - database-deadlocks

I am doing a research but any relevant information is hard to find. I stumbled upon this problem:
Produce a wait-for-graph for the following transaction scenario and determine whether
deadlock exists.
Transaction:
T1
T2
T3
T4
T5
T6
T7
T8
T9
T10
Data items locked by transaction:
X1,X2,X3
X4,X5,X6
X7,X8
X9,X10
X11,X12
X13,X14
X15
X1111
X115
X199
Data items transaction is waiting for:
X4,X5,X6,X7
X7,X8,X9
X1,X10,X111
X7,X11,X12
X5
X6,X1,X2,X3,X11,X12
X5
X1,X115
X1
X11,X12
Now, as far as I've seen on transaction management, this striked me as quite hard. Can someone provide reference to explanation how to solve this type of problem, or help anyhow?

As is quite common, the key to resolving some problems is choosing a good representation. If you represent your problem in tabular form:
T1 => { locked => [ qw( X1 X2 X3 ) ], waiting => [ qw( X4 X5 X6 X7 ) ] },
T2 => { locked => [ qw( X4 X5 X6 ) ], waiting => [ qw( X7 X8 X9 ) ] },
T3 => { locked => [ qw( X7 X8 ) ], waiting => [ qw( X1 X10 X111 ) ] },
T4 => { locked => [ qw( X9 X10 ) ], waiting => [ qw( X7 X11 X12 ) ] },
T5 => { locked => [ qw( X11 X12 ) ], waiting => [ qw( X5 ) ] },
T6 => { locked => [ qw( X13 X14 ) ], waiting => [ qw( X6 X1 X2 X3 X11 X12 ) ] },
T7 => { locked => [ qw( X15 ) ], waiting => [ qw( X5 ) ] },
T8 => { locked => [ qw( X1111 ) ], waiting => [ qw( X1 X115 ) ] },
T9 => { locked => [ qw( X115 ) ], waiting => [ qw( X1 ) ] },
T10 => { locked => [ qw( X199 ) ], waiting => [ qw( X11 X12 ) ] },
then you can reason more effectively about the problem at hand. It's easy to see what resources a certain transaction is waiting for, and from there you can see which transactions holds those resources. Apply that reasoning recursively. If you end up in a cycle, you've just found a deadlock.
'Course, the representation can even be better:
use strict;
use warnings;
use Data::Dumper;
my %transactions = (
T1 => { locked => [ qw( X1 X2 X3 ) ], waiting => [ qw( X4 X5 X6 X7 ) ] },
T2 => { locked => [ qw( X4 X5 X6 ) ], waiting => [ qw( X7 X8 X9 ) ] },
T3 => { locked => [ qw( X7 X8 ) ], waiting => [ qw( X1 X10 X111 ) ] },
T4 => { locked => [ qw( X9 X10 ) ], waiting => [ qw( X7 X11 X12 ) ] },
T5 => { locked => [ qw( X11 X12 ) ], waiting => [ qw( X5 ) ] },
T6 => { locked => [ qw( X13 X14 ) ], waiting => [ qw( X6 X1 X2 X3 X11 X12 ) ] },
T7 => { locked => [ qw( X15 ) ], waiting => [ qw( X5 ) ] },
T8 => { locked => [ qw( X1111 ) ], waiting => [ qw( X1 X115 ) ] },
T9 => { locked => [ qw( X115 ) ], waiting => [ qw( X1 ) ] },
T10 => { locked => [ qw( X199 ) ], waiting => [ qw( X11 X12 ) ] },
);
# get a data-item -> transaction mapping
my %items;
for my $transaction (keys %transactions) {
for my $item (#{$transactions{$transaction}->{locked}}) {
$items{$item} = $transaction;
}
}
my #nodes;
my #edges;
for my $transaction (keys %transactions) {
push #nodes, $transaction;
for my $item (#{$transactions{$transaction}->{waiting}}) {
push #edges, { source => $transaction, dest => $items{$item}, item => $item } if $items{$item};
}
}
print "digraph tx_dependencies {\n";
print " $_ label=$_;\n" for #nodes;
print " #{[ $_->{source} ]} -> #{[ $_->{dest} ]} [label=#{[ $_->{item} ]}];\n" for #edges;
print "}\n";
This program spews a graphviz file, which when massaged appropriately with dot ends up as:

Related

Convert Array Into String Array

array:5 [
0 => array:1 [
"location_id" => 1
]
1 => array:1 [
"location_id" => 4
]
2 => array:1 [
"location_id" => 6
]
3 => array:1 [
"location_id" => 7
]
4 => array:1 [
"location_id" => 8
]
]
convert this into ["1","4","6","7","8",]
as used this ["1","4","6","7","8",]array in different query
You can use Laravel Collection pluck method to only return property which you want from each array item, and after that flatten the result array with flatten
$data = [
[
"location_id" => 1
],
[
"location_id" => 4
],
[
"location_id" => 6
],
[
"location_id" => 7
],
[
"location_id" => 8
]
];
$result = collect($data)->pluck('location_id')->flatten();
You can use the laravel helper array flatten method: Read more about it from here: https://laravel.com/docs/9.x/helpers#method-array-flatten
// Add the helper class call in the controller header
use Illuminate\Support\Arr;
// The actual array
$array = [
0 => [
"location_id" => 1
],
1 => [
"location_id" => 4
],
2 => [
"location_id" => 6
],
3 => [
"location_id" => 7
],
4 => [
"location_id" => 8
]
];
// Flatten the array function
$result = Arr::flatten($array);
Results:
['1','4','6','7','8']
Not as clean you might want but get the job done:
$resultSet = collect($data)->map(function($item){
return $item['location_id'];
})->toArray();
$resultString = "[";
foreach($resultSet as $item){
$resultString .= "'{$item}'" . ",";
}
$resultString = rtrim($resultString, ","); // produces this: "['1','4','6','7','8']"
$resultString .= "]";
dd($resultString);
You can use the laravel helper array pluck method Read more about it from here: https://laravel.com/docs/9.x/helpers#method-array-pluck
$array = [
0 => [
"location_id" => 1
],
1 => [
"location_id" => 4
],
2 => [
"location_id" => 6
],
3 => [
"location_id" => 7
],
4 => [
"location_id" => 8
]
];
$data = \Arr::pluck($array, 'location_id'); // [1,4,6,7,8]
$result = array_map('strrev', $data);
Result
["1","4","6","7","8"]

Karate Framework; Reuse array of the values to paste the values into another json with N nested elements

Hi Team!
Here is my question - how to reuse the array of the values from json1 and paste the values one by one into a json2; and create JSON with 1 parent and nested elements
json1;
[
"EAID_6F41E794_9FE8_447a_9AA2_BD5CA941B0A8",
"EAID_7144A90E_3566_43e1_A071_9D9977B99E8A",
"EAID_14F85DAB_7BF7_4ad1_8DBF_F2ABEBE7E35A",
"EAID_DEDC0908_FDE9_4384_8DED_B9FF30760C6C",
"EAID_6F41E794_9FE8_447a_9AA2_BD5CA941B0A8",
"EAID_14F85DAB_7BF7_4ad1_8DBF_F2ABEBE7E35A",
"EAID_6F41E794_9FE8_447a_9AA2_BD5CA941B0A8",
"EAID_7144A90E_3566_43e1_A071_9D9977B99E8A",
"_19_0_3_8aa01e4_1610562779046_96927_69106",
"_19_0_3_8aa01e4_1610562779046_96927_69106"
]
{
"orders": [
{
"values": [
"EAID_6F41E794_9FE8_447a_9AA2_BD5CA941B0A8"
]
},
{
"values": [
"EAID_7144A90E_3566_43e1_A071_9D9977B99E8A"
]
}
]
}
Here you go:
* def fun = function(x){ return { values: [ x ] } }
* def result = karate.map(json1, fun)
* def json2 = { orders: '#(result)' }
* print json2
Please refer the docs: https://github.com/karatelabs/karate#json-transforms
Just for fun, here's an alternate more concise solution:
* def fun = x => ({ values: [ x ] })
* def json2 = ({ orders: json1.map(fun) })
* print json2
Simpler version:

Drupal create node by post Api call fail with message "Could not determine entity type bundle: \\u0022type\\u0022 field is missing."}

I'm trying to create a node via drupal API but I have this error:
Got error 'PHP message: PHP Fatal error: Uncaught GuzzleHttp\\Exception\\ClientException: Client error: `POST https://site.it/entity/node?_format=hal_json` resulted in a `422 Unprocessable Entity` response:\n{"message":"Could not determine entity type bundle: \\u0022type\\u0022 field is missing."}
this is my function:
public function createFaq($notes, $telegram_id){
$url = "/entity/node?_format=hal_json";
$opt = [
'headers' => self::$baseHeader,
'body' => json_encode([
[
'type' => [ ['target_id' => 'faq'] ],
'title' => 'title',
'utente' => [ [ 'target_id' => '123462' ] ],
'field_domanda' => [ [ 'value' => $notes['domanda'] ] ],
'field_presenza' => [ [ 'value' => $notes['presenza'] == "Si"? true : false ] ],
]
])
];
$response = $this->client->request('POST', $url , $opt);
$r = json_decode( $response->getBody());
return $r;
}
But i't really strange because this other function is working
public static function createUser($title){
$url= "/entity/node?_format=hal_json";
$opt = [
'headers' => self::$baseHeader,
'body' => json_encode([
'title' => [ [ 'value' => $title ] ],
'type' => [ [ 'target_id' => 'article' ] ],
])
];
$response = $this->client->request('POST', $url , $opt);
$r = json_decode( $response->getBody());
return $r;
}
Can someone understood my error?
This is because the json data are enclosed in square brackets twice, just remove one pair :
$opt = [
'headers' => self::$baseHeader,
'body' => json_encode([
//[
'type' => [ ['target_id' => 'faq'] ],
'title' => 'title',
'utente' => [ [ 'target_id' => '123462' ] ],
'field_domanda' => [ [ 'value' => $notes['domanda'] ] ],
'field_presenza' => [ [ 'value' => $notes['presenza'] == "Si"? true : false ] ],
//]
])
];

Call a controller with json data on api plateform

I have build my Application with make:entity,
After I create a query who link all the table to get what I want ( a bit of all tables )
My query is working but now I want to use API Plateform to handling routes.
But I find no way to call my controller with API Plateform notation.
Annotation on Caractéristiques entity.
#[ApiResource(collectionOperations: ['requete' => [
'method' => 'get',
'path' => '/requete',
'controller' => ApiRequeteController::class,
'openapi_context' => [
'summary' => 'get requete',
'requestBody' => [
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' =>
[
'montant' => ['type' => 'int'],
'loc' => ['type' => 'string'],
'stat' => ['type' => 'string'],
'type' => ['type' => 'string'],
'sect' => ['type' => 'string'],
],
],
'example' => [
'montant' => 1000000,
'loc' => "test",
'stat' => "test",
'type' => "test",
'sect' => "test",
],
],
],
],
],
],
])]
I have found this way but not working.
give me:
syntax error, unexpected '=>' (T_DOUBLE_ARROW)
on
'method' => 'get',
Any way to do this ?
With POST and another writing
* collectionOperations= {"requete" = {
* "method" = "POST",
* "path" = "/requete",
* "controller" = App\Controller\ApiRequeteController::class,
* "openapi_context" = {
* "summary" = "get requete",
* "requestBody" = {
* "content" = {
* "application/json" = {
* "schema" = {
* "type" = "object",
* "properties" =
* {
* "montant" = {"type" = "int"},
* "loc" = {"type" = "string"},
* "stat" = {"type" = "string"},
* "type" = {"type" = "string"},
* "sect" = {"type" = "string"},
* },
* },
* "example" = {
* "montant" = 1000000,
* "loc" = "test",
* "stat" = "test",
* "type" = "test",
* "sect" = "test",
* },
* },
* },
* },
* }
* }
* }
* )
*/

Laravel 5.3 - Missing "value" attribute in query builder

I am new to Laravel and Yajra datatable. I have developed a web application (In windows XAMPP) and everything works perfectly until I upload my project in shared hosting (UNIX) recently, the datatable unable to load the view and throwing the error message.
The error message I get is:
ErrorException in Request.php line 38:
Undefined index: value
in Request.php line 38
at HandleExceptions->handleError('8', 'Undefined index: value', '/home/posgb/public_html/boatMain/vendor/yajra/laravel-datatables-oracle/src/Request.php', '38', array()) in Request.php line 38
I have compared DD results of my query builder output in both my machine and server and found that the "value" attribute was missing from the "search" array.
My query:
$query = DB::table('item_subcat')
->leftJoin('item_customized', 'item_subcat.subcatID', '=', 'item_customized.subcatID')
->join('item_cat', 'item_subcat.itemCatID', '=', 'item_cat.itemCatID')
->select(array('item_subcat.subcatID', 'item_subcat.itemCode', 'item_subcat.itemName', 'item_cat.itemCatName', 'item_customized.customize_name', DB::raw('IF(item_subcat.is_categorize = "0", item_subcat.itemPrice, item_customized.price) AS ITEMPRICE'), 'item_subcat.is_activate', 'item_customized.itemCustomID'));
dd($query);
DD results in my pc:
#parameters: array:7 [
"draw" => "1"
"columns" => array:7 [
0 => array:5 [ …5]
1 => array:5 [ …5]
2 => array:5 [ …5]
3 => array:5 [ …5]
4 => array:5 [ …5]
5 => array:5 [ …5]
6 => array:5 [ …5]
]
"order" => array:1 [
0 => array:2 [ …2]
]
"start" => "0"
"length" => "10"
"search" => array:2 [
"value" => "" /*This is the missing value */
"regex" => "false"
]
"branch" => "ALL"
]
}
DD result in my server:
+request: ParameterBag {#41
#parameters: array:7 [
"draw" => "1"
"columns" => array:7 [
0 => array:5 [ …5]
1 => array:5 [ …5]
2 => array:5 [ …5]
3 => array:5 [ …5]
4 => array:5 [ …5]
5 => array:5 [ …5]
6 => array:5 [ …5]
]
"order" => array:1 [
0 => array:2 [ …2]
]
"start" => "0"
"length" => "10"
"search" => array:1 [
"regex" => "false"
]
"branch" => "ALL"
]
}
Please can advise me where should I look into the missing "value" in array, as it cause me unable to generate the datatable. TYVM for those spent times to look at this.
The reason was due to PHP.ini settings in my server which disallow null value in GET and POST request by default.