Couchbase CAS NOT Working, when I upsert muli thread environment - couchbase

I use couchbase.
In order to count the API's call volume, count is added to the couchbase document per call.
The actual call amount and count did not match, so I checked.
The same count was duplicated and recorded.
if(bucket.exit(documentId)){
bucket.getAndLock(documentId);
count + 1
if(bucket.unlock(documentId, cas)){
bucket.upsert(JsonDocument);
log.info(JsonDocument`s count);
}
} else{
bucket.upsert(new JsonDocument);
}
//under is log example
log1 - count : 1
log2 - count : 2
log3 - count : 2
log4 - count : 3
Upper process working in akka cluster.
I am wonder why same count is occur.
Pleas help me.

Related

JDBC results set iteration sometimes goes fast and often times goes slow (75x speed difference)

I'm developing a GAS script to retrieve data (~15,000 rows) from an Azure SQL database table into a Sheets spreadsheet. The code works fine but there are huge speed differences from run to run in the results.next() loop
Below is my code (some variable declarations and private stuff removed) and below the code is logs from three executions
function readData() {
Logger.log('Establishing DB connection')
let conn = Jdbc.getConnection(connectionString , user, userPwd);
Logger.log('Executing query')
let stmt = conn.createStatement();
let results = stmt.executeQuery("SELECT * FROM VIEW");
let contents = []
let i = 0
Logger.log("Iterating result set and adding into array")
while (results.next()) {
contents.push([
results.getInt(1),
results.getString(2),
results.getInt(3),
results.getString(4),
results.getInt(5),
results.getString(6),
results.getString(7),
results.getString(8),
results.getFloat(9),
results.getFloat(10),
results.getInt(11),
results.getString(12),
results.getInt(13),
results.getInt(14),
results.getInt(15),
])
//Make log entry every 100th iteration and display the average passed ms per iteration
i++
if(i % 100 == 0){
Logger.log(i)
finish = new Date().getMilliseconds();
Logger.log((finish - start) / i)
}
}
sheet.getRange(2,1,sheet.getLastRow(),15).clearContent()
sheet.getRange(2,1,contents.length,15).setValues(contents)
results.close();
stmt.close();
}
Fast run:
8:41:47 AM Info 11100 Records added
8:41:47 AM Info 8.43ms on average per record
8:41:47 AM Info
8:41:47 AM Info 11200 Records added
8:41:47 AM Info 8.42ms on average per record
8:41:47 AM Info
8:41:48 AM Info 11300 Records added
8:41:48 AM Info 8.42ms on average per record
Slow run:
8:48:01 AM Info 100 Records added
8:48:01 AM Info 162.30ms on average per record
8:48:01 AM Info
8:48:17 AM Info 200 Records added
8:48:17 AM Info 162.84ms on average per record
8:48:17 AM Info
8:48:34 AM Info 300 Records added
8:48:34 AM Info 163.11ms on average per record
Extremely slow run:
8:56:46 AM Info 300 Records added
8:56:46 AM Info 629.08ms on average per record
8:56:46 AM Info
8:57:49 AM Info 400 Records added
8:57:49 AM Info 628.95ms on average per record
8:57:49 AM Info
8:58:52 AM Info 500 Records added
8:58:52 AM Info 629.70ms on average per record
So as seen from above logs, one run of the script can go roughly 75x faster than another. The time per iteration stays the same within a specific run. I'm pretty baffled as to how that's possible. Is there something about the result set object I don't know?
You can submit a bug on Google's Issue Tracker using the following template for Apps Script:
https://issuetracker.google.com/issues/new?component=191640&template=823905
If you have a workspace account, you can also contact Google Workspace support so they can take a look at your issue.

Difference between two time values in SSRS report

I have the following select statement:
SELECT [TR_DATE]
,[TR_TIME]
,RIGHT('000000' + CONVERT(varchar,TR_TIME), 6)
,TIMEFROMPARTS(SUBSTRING(RIGHT('000000' + CONVERT(varchar,TR_TIME), 6),1,2), SUBSTRING(RIGHT('000000' + CONVERT(varchar,TR_TIME), 6),3,2), SUBSTRING(RIGHT('000000' + CONVERT(varchar,TR_TIME), 6),5,2),0,0) as trtime
,[ET_TYPENO]
,[ET_NAME]
FROM [DB400].[dbo].[TRANSACTIONREPORT]
where DEPT_NAME = 'GIJIMA AST HOLDINGS (PTY) LTD'
/*and LOC_NAME = 'Front Door and Gate'*/
and TR_DATE between '20200120' and '20200130'
order by TR_DATE, MST_LASTNAME, MST_FIRSTNAME, TR_TIME
which returns the following data:
I would like to use this to calculate the time the was spent in the building.
Note that ET_TYPENO = 1 equates to "Allowed Normal In" and ET_TYPENO = 2 to "Allowed Normal Out"
I have the following expression inside an ssrs report
=iif(Fields!ET_TYPENO.Value=2,
DateDiff(DateInterval.Hour, previous(Fields!trtime.Value),Fields!trtime.Value),
"")
But it resolves to the following #Error.
UPDATE
Expected Result
Calculate the time difference between the "Allowed Nornmal In" event and the "Allowed Normal Out" event.
Take line 2 and 3 for example. "Allowed Nornmal In" occured at 07:23:19 and "Allowed Normal Out" occured at 08:55:48. I need it to return the time difference between these two times. I.E. 1:32:29.
The trtime needs to be converted to a DATE type with the CDATE() function to use the DATEDIFF function.
=IIF(Fields!ET_TYPENO.Value = "OUT",
DateDiff(DateInterval.Hour, CDATE(previous(Fields!trtime.Value)), CDATE(Fields!trtime.Value)),
NOTHING)
Also, shouldn't Fields!ET_TYPENO.Value = 1 ?
Taking the suggestion from Honnover Fist's answer that the parameter of the DateDiff need to be Dates instead of Times. (The Documentation does say that a Time will work). I have changed my query to a DATETIMEFROMPARTS() instead of a TIMEFROMPARTS().
Then I changed the condition to the below code so that the hours would be displayed more accurately.
=IIF(Fields!ET_TYPENO.Value = 2,
DateDiff(DateInterval.Minute, previous(Fields!TR_DATETIME.Value), Fields!TR_DATETIME.Value) / 60,
NOTHING)

BigCommerce Stencil - Product Variant Stock Levels

A client wants to set up A/B testing on the Product Detail Page related to the stock_level of a product's variants. Once the user selects their options, if the quantity is less than 5, I'd show something like "Hurry, only 3 more in stock"...
I believe I have the correct Inventory settings enabled, because I can retrieve the stock_level of a product without options.
Has anyone had success pulling variant SKU stock_levels in stencil?
Thanks
This can be done using javascript in the assets/js/theme/common/product-details.js file. On initial page load and each time a product option is changed, there is a function updateView(data) that is called. The data parameter contains all the info you need for the selected variation.
Starting on line 285, replace this:
updateView(data) {
const viewModel = this.getViewModel(this.$scope);
this.showMessageBox(data.stock_message || data.purchasing_message);
with this:
updateView(data) {
const viewModel = this.getViewModel(this.$scope);
if(data.stock < "5") {
data.stock_message = "Hurry, only " + data.stock + " left!";
}
this.showMessageBox(data.stock_message || data.purchasing_message);

Doctrine2 query behavior with groupBy

I have the following custom method in the repo:
$query = $qb->select('Client', 'Organization')
->from(':Client', 'Client')
->leftJoin('Client.organizations', 'Organization');
--different searh conditions--
Then I use paginator to get the results:
$paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query->getQuery());
$clients = $paginator->getQuery()
->setMaxResults($length)
->setFirstResult($start);
Here where the magic comes.
I set length to 10 and first result to 0. So basicaly I should get 10 results on the page. However if there are 5 Organizations for the Client (Client mtm Organization), there will be 5 results, if there are 7 Organizations - 3 results.
But if I add
$query->groupBy('Client');
Then all is "ok" with the root level of results: i.e. there are 10 Clients on the page, but there is not all of the Organizations (max 1).
Did anyone experience the same issue? Any thoughts, suggestions?
It probably counts the same item several times.
Try once to add a distinct clause to your query.
$query = $qb->select('Client', 'Organization')
->from(':Client', 'Client')
->leftJoin('Client.organizations', 'Organization');
->distinct();

Order of execution for a recursive Fibonacci method

ex:
public static int fibb (int n) {
if(n==0||n==1)
return 1;
else{
return fibb(n-1)+fibb(n-2);
}
}
How will the line fibb(n-1)+fibb(n-2) be executed .. like will fibb(n-1) finish first the fibb(n-2) starts or how exactly, I'm fairly new to recursion and can't seem to wrap my head around how it works.
Help appreciated.
First, the recursive calls will be executed (the order in which being dependent on your programming language), then their results will be summed together.
fibb(3) returns fibb(2) + fibb(1)
fibb(2) returns fibb(1) + fibb (0)
so you get 1 + 1 + 1 = 3
fibb(4) returns fibb(3) + fibb(2), we know fibb(3) returns three from above,
fibb(2) returns fibb(1) + fibb(0) also from above,
so fibb(4) returns 3 + 2 = 5
It's important to notice that with this implementation you must computer each previous Fibonacci number twice. Which means by the time you get to around ~20 (guess) it's going to get VERY slow.