TL; DR:我要么失去理智,要么neo4j的交易稍有破产.看起来未提交的节点在提交的事务之外可用,缺少属性 - 或者同样奇怪的东西.
我们的node.js应用程序使用neo4j.它的一部分必须生成唯一的ID.我们有以下cypher查询,用于查找最后一个:Id类型的节点并尝试使用提交新:Id节点last_uuid+1.
MATCH (i:Id) WITH i ORDER BY i.uuid DESC LIMIT 1 #with it like a sub-return, will "run" the rest with the last i at read-time
CREATE (n:Id {label:"Test"})
SET n.uuid = i.uuid + 1
RETURN n
Run Code Online (Sandbox Code Playgroud)
还有一个约束:
neo4j-sh (?)$ schema
Indexes
ON :Id(uuid) ONLINE (for uniqueness constraint)
Constraints
ON (id:Id) ASSERT id.uuid IS UNIQUE
Run Code Online (Sandbox Code Playgroud)
并初始化DB (:Id{uuid:1})以启动这种快乐.
应用程序代码基本上会重试上述查询,直到成功为止.如果两个或多个Id创建请求同时命中,其中只有一个将通过,其余的将失败并由应用程序代码重试.
这是有效的,直到我们并行尝试.
代码在没有uuid的情况下开始返回数据.经过大量的调查,结果是查询的写入部分(CREATE ...)以某种方式从MATCH接收:Id,没有.uuid(或其他)属性.这不应该是可能的.这是在这些节点上运行的唯一代码.
最奇怪的(也许)的事情是,如果我救i的nodeid,以找到在数据库节点,它确实存在,并有.uuid属性.
为了隔离这种行为,我编写了一个PoC: …
我在使用neo4j唯一约束方面遇到了一些麻烦,其中CREATE cypher语句由于节点已经存在而无法执行.问题是,它不存在(存在).此外,这个确切的过程与昨天的确切数据有关.
我的neo4j版本是ubuntu 12.04.3上的社区2.0.0(发布).这是我目前的情况:
我的约束:
tas@vtas:~$ neo4j-shell
neo4j-sh (?)$ schema
Indexes
ON :ConsumerUser(tokens) ONLINE
ON :Id(uuid) ONLINE (for uniqueness constraint) #relevant
ON :User(email) ONLINE (for uniqueness constraint)
ON :User(username) ONLINE (for uniqueness constraint)
Constraints
ON (user:User) ASSERT user.email IS UNIQUE
ON (user:User) ASSERT user.username IS UNIQUE
ON (id:Id) ASSERT id.uuid IS UNIQUE #relevant
Run Code Online (Sandbox Code Playgroud)
:Id.uuid应该是唯一的.
我没有任何数据:
neo4j-sh (?)$ dump
begin
create index on :`ConsumerUser`(`tokens`);
create index on :`Id`(`uuid`);
create index on :`User`(`email`);
create index on :`User`(`username`);
;
Run Code Online (Sandbox Code Playgroud)
(也用cypher验证MATCH (n) return …
我试图使一个简单的.htaccess重写规则可以工作,但我似乎无法解决。
我的.htaccess如下所示:
RewriteEngine On
RewriteRule ^api$ phpinfo.php
ErrorDocument 404 /error.php
php_flag display_errors on
php_flag display_startup_errors on
php_flag file_uploads on
php_value error_reporting 2047
php_value max_input_time 60
php_value post_max_size 8M
php_value upload_max_filesize 2M
Run Code Online (Sandbox Code Playgroud)
访问时/api,出现404错误,提示/api找不到。
我的Apache conf文件看起来像:
<IfModule mod_ssl.c>
NameVirtualHost 10.104.17.3:443
<VirtualHost 10.104.17.3:443>
ServerName orddev.foo.com.au
DocumentRoot /var/www/orddev.foo.com.au___443/html
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory "/var/www/orddev.foo.com.au___443/html">
Options FollowSymLinks MultiViews IncludesNOEXEC
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<IfModule mod_php5.c>
php_admin_value upload_tmp_dir "/var/www/orders.foo.com.au___443/resources/_tmp/upload/"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond …Run Code Online (Sandbox Code Playgroud) 我在操场上玩 Go 泛型,试图编写一些通用数组函数。
https://go2goplay.golang.org/p/PFb1jhy1fML
package main
import (
"fmt"
)
func array_has[T any](haystack []T, needle T) bool {
for _, val := range haystack {
if val == needle {
return true
}
}
return false
}
func main() {
arr := []string{"A","B","C"}
fmt.Println(array_has(arr, "T"))
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
type checking failed for main
prog.go2:9:6: cannot compare val == needle (operator == not defined for T)
Run Code Online (Sandbox Code Playgroud)
我可以通过使用反射来解决它:
if reflect.ValueOf(val).Interface() == reflect.ValueOf(needle).Interface()
Go2 游乐场:https ://go2goplay.golang.org/p/9ZVZafQ_9JK
但是,是否有一个(内部?)“可比较”类型的接口==,为此我可以使用它来代替any?
真的有甚至不支持与 比较的类型 …
cypher ×2
neo4j ×2
.htaccess ×1
apache ×1
constraints ×1
generics ×1
go ×1
node-neo4j ×1
transactions ×1